简体   繁体   中英

creating sub-matrices inside a big one in Eigen Library

I would like to construct the following matrix

              A(3x3)              B(3x3N) 
    F     = [|1 0 0|  |0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0|;
(6x3+3N)     |0 1 0|  |0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0|;
             |0 0 1|  |0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0|;
             -------  -----------------------------------
             |0 0 0|  |0 0 0 1 0 0 0 0 0 0 0 0 ... 0 0 0|;
             |0 0 0|  |0 0 0 0 1 0 0 0 0 0 0 0 ... 0 0 0|;
             |0 0 0|  |0 0 0 0 0 1 0 0 0 0 0 0 ... 0 0 0|];
              C(3x3)              D(3x3N)

B & C are always zeros. A is an identity matrix. D is tricky. The ones are specified based on an index. For example, if the index is 0 , then D is

                   |1 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0|;
                   |0 1 0 0 0 0 0 0 0 0 0 0 ... 0 0 0|;
                   |0 0 1 0 0 0 0 0 0 0 0 0 ... 0 0 0|;
                                D(3x3N)

if the index is 1 then D is

                   |0 0 0 1 0 0 0 0 0 0 0 0 ... 0 0 0|;
                   |0 0 0 0 1 0 0 0 0 0 0 0 ... 0 0 0|;
                   |0 0 0 0 0 1 0 0 0 0 0 0 ... 0 0 0|;
                                D(3x3N)

How is it possible to fulfil this procedure in Eigen Library? I know how to create matrices in Eigen but I don't know how to construct them as a one matrix.

Have a look at the page Advanced initialization in Eigen. I think the following (untested) code constructs the matrix you want:

MatrixXd F(6, 3 + 3 * N);  // you need to specify the size before doing F << ...
F << MatrixXd::Identity(3, 3),   // matrix A
     MatrixXd::Zero(3, 3 * N),   // matrix B
     MatrixXd::Zero(3, 3 + 3 * index),   // matrix C plus left zero block in D
     MatrixXd::Identity(3, 3),   // indentity block in D
     MatrixXd::Zero(3, 3 * (N - index - 1));  // right zero block in D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM