I have four column vectors. I need to append them to make a four by four matrix. Is there a constructor or something for that?
Eigen offers a comma initializer syntax which allows the user to easily set all the coefficients of a matrix, vector or array. Simply list the coefficients, starting at the top-left corner and moving from left to right and from the top to the bottom. The size of the object needs to be specified beforehand.
We define the matrix-vector product only for the case when the number of columns in A equals the number of rows in x. So, if A is an m×n matrix (i.e., with n columns), then the product Ax is defined for n×1 column vectors x. If we let Ax=b, then b is an m×1 column vector.
Vectors. As mentioned above, in Eigen, vectors are just a special case of matrices, with either 1 row or 1 column. The case where they have 1 column is the most common; such vectors are called column-vectors, often abbreviated as just vectors. In the other case where they have 1 row, they are called row-vectors.
You can also append them using the comma initializer syntax:
m << v1, v2, v3, v4;
The matrix m
must have been properly resized first.
A quick check on the docs:
Vector4f v1(1,0,0,0);
Vector4f v2(0,1,0,0);
Vector4f v3(0,0,1,0);
Vector4f v4(0,0,0,1);
Matrix4f m;
m.row(0) = v1;
m.row(1) = v2;
m.row(2) = v3;
m.row(3) = v4;
std::cout << m << std::endl;
output:
1,0,0,0
0,1,0,0
0,0,1,0
0,0,0,1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With