Eigen是基于C++模板的矩阵运算库,在SLAM中是必须把握的。Eigen有一个特地的中央就是它是一个齐全用头文件搭建的库,不须要链接库文件
Eigen中矩阵的定义

在CMakeLists.txt中指定Eigen的头文件目录

include_directories("usr/include/eigen3")
//Eigen外围局部#include <Eigen/Core>//用于浓密矩阵的代数运算#include <Eigen/Dense>Matrix<double, 3, 3> A;               Matrix<double, 3, Dynamic> B;         Matrix<double, Dynamic, Dynamic> C;   // 反对动静大小的矩阵Matrix3f P, Q, R;                     // 3x3 float matrix.Vector3f x, y, z;                     // 3x1 float matrix.RowVector3f a, b, c;                  // 1x3 float matrix.VectorXd v;                           // Dynamic column vector of doubles

矩阵类型转换。
Eigen矩阵不反对主动类型晋升,必须显式地对矩阵类型进行转换。

//// Type conversion// Eigen                           // MatlabA.cast<double>();                  // double(A)A.cast<float>();                   // single(A)A.cast<int>();                     // int32(A)A.real();                          // real(A)A.imag();                          // imag(A)// if the original type equals destination type, no work is done

Eigen 求解线性方程组 Ax = b,个别不会间接求逆,而是采纳矩阵合成,速度会快很多

x = A.ldlt().solve(b));  // A sym. p.s.d.    #include <Eigen/Cholesky>x = A.llt().solve(b));  // A sym. p.d.      #include <Eigen/Cholesky>x = A.lu().solve(b));  // Stable and fast. #include <Eigen/LU>x = A.qr().solve(b));  // No pivoting.     #include <Eigen/QR>x = A.svd().solve(b));  // Stable, slowest. #include <Eigen/SVD>

Eigen 求矩阵特征值

A.eigenvalues();                  // eig(A);EigenSolver<Matrix3d> eig(A);     // [vec val] = eig(A)eig.eigenvalues();                // diag(val)eig.eigenvectors();               // vec

Eigen 的一些矩阵操作

trace(); //求迹inverse(); //求逆矩阵determinant(); //求行列式