All vectors and matrices in Eigen are Eigen::Matrix, which is a template class. Its first three parameters are: data type, row, column. Declaring a 2x3 float matrix:
At the same time, Eigen provides many built-in types via typdef, but the bottom layer is still Eigen::Matrix. For example, Vector3d is essentially Eigen::Matrix<double, 3, 1>.
Matrix3d is also essentially the same as Eigen::Matrix<double, 3,3>.
If we’re not sure about the size of the matrix, we can use one with dynamic size:
Input and output operations:
Using loops to access elements in the matrix:
We can easily multiply a matrix with a vector (but actually still matrices and matrices). In Eigen you can’t mix two different types of matrices, like this is wrong:
We need to explicitly convert by casting:
Also you can’t misjudge the dimensions of the matrix like this:
Matrix operations:
Eigenvalues;
Solving equations also works! We can solve the equation of matrix_NN * x = v_Nd. The size of N is defined in the previous macro, which is generated by a random number. Direct inversion is the most direct but the number of operations is large.