Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make a matrix out of vectors in eigen?

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?

like image 868
DanielLC Avatar asked May 09 '13 20:05

DanielLC


People also ask

How do you initialize a matrix in Eigen?

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.

Can we define matrix from a vector?

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.

What is Eigen 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.


2 Answers

You can also append them using the comma initializer syntax:

m << v1, v2, v3, v4;

The matrix m must have been properly resized first.

like image 141
ggael Avatar answered Oct 03 '22 14:10

ggael


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
like image 28
Ian Medeiros Avatar answered Oct 03 '22 14:10

Ian Medeiros