Eigen (C++)
Eigen is an efficient high-level C++ library for linear algebra related computations, which only depends on the C++ standard library.
Matrix-Vector definitions are as follows:
- Explicit
Eigen::Matrix <data type, rows, cols>
- 3x4 matrix of floats:
Eigen::Matrix <float, 3, 4> matA;
- Dynamic matrix of doubles:
Eigen::Matrix <double, Eigen::Dynamic, Eigen::Dynamic> matA;
- 3x4 matrix of floats:
- Typedef
Eigen::Matrixntype
wheren
is some integer,type
is the data type.- 4x4 matrix of floats:
Eigen::Matrix4f matA;
- Dynamic matrix of doubles:
Eigen::MatrixXd matA;
- 4x4 matrix of floats:
- Typedef
Eigen::Vectorntype
- 3x1 vector of floats:
Eigen::Vector3f vecb;
- Dynamic vector of doubles:
Eigen::VectorXd vecb;
- 3x1 vector of floats:
The fact that we only pass one number to the Explicit matrices hint that they can only be used for square matrices.
Matrices can be initialized via functions, or manually. Accessing the values are straightforward as well.
// initialize via functions matA.setZero(); matA.setOnes(); matA.setIdentity(); matA.setConstant(value); matA.setRandom(); // initialize manually Eigen::Matrix2f matA; matA << 1.3, 4.2, 7.5, 9.7; // matA = [ 1.3 4.2 ] // [ 7.5 9.7 ] // access single entry matA(0,0) // 1.3 // access block matrix matA(a,b,c,d) // returns block with (a,b) upper left corner, (c,d) lower right corner // access rows and columns matA.row(1) // [1.3 4.2] matA.col(0) // [1.3 7.5]^T