Reputation: 5741
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.
Upvotes: 1
Views: 287
Reputation: 4532
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
Upvotes: 2