Eigen常規矩陣定義
1.使用
Eigen的使用在官網上有詳細的介紹,這里對我學習過程中用到的基本操作進行介紹。首先是矩陣的定義。
在矩陣類的模板參數共有6個。一般情況下我們只需要關注前三個參數即可。前三個模板參數如下所示:
Matrix<typename Scalar,int RowsAtCompileTime,int ColsAtCompileTime>
- Scalar參數為矩陣元素的類型,該參數可以是int,float,double等。
- RowsAtCompileTime和ColsAtCompileTime是矩陣的行數和列數。
如Matrix<float,4,4> M44
是定義一個4×4的矩陣,矩陣元素以float類型存儲。直接使用矩陣模板定義一個矩陣往往會覺得麻煩,Eigen提供了一些基本矩陣的別名定義,如typedef Matrix<float,4,4> Matrix4f
.下面是一些內置的別名定義.來源於官方手冊:
typedef Matrix< std::complex<double> , 2 , 2 > Matrix2cd typedef Matrix< std::complex<float> , 2 , 2 > Matrix2cf typedef Matrix< double , 2 , 2 > Matrix2d typedef Matrix< float , 2 , 2 > Matrix2f typedef Matrix< int , 2 , 2 > Matrix2i typedef Matrix< std::complex<double> , 3 , 3 > Matrix3cd typedef Matrix< std::complex<float> , 3 , 3 > Matrix3cf typedef Matrix< double , 3 , 3 > Matrix3d typedef Matrix< float , 3 , 3 > Matrix3f typedef Matrix< int , 3 , 3 > Matrix3i typedef Matrix< std::complex<double> , 4 , 4 > Matrix4cd typedef Matrix< std::complex<float> , 4 , 4 > Matrix4cf typedef Matrix< double , 4 , 4 > Matrix4d typedef Matrix< float , 4 , 4 > Matrix4f typedef Matrix< int , 4 , 4 > Matrix4i typedef Matrix< std::complex<double> , Dynamic , Dynamic > MatrixXcd typedef Matrix< std::complex<float> , Dynamic , Dynamic > MatrixXcf typedef Matrix< double , Dynamic , Dynamic > MatrixXd typedef Matrix< float , Dynamic , Dynamic > MatrixXf typedef Matrix< int , Dynamic , Dynamic > MatrixXi typedef Matrix< std::complex<double> , 1, 2 > RowVector2cd typedef Matrix< std::complex<float> , 1, 2 > RowVector2cf typedef Matrix< double , 1, 2 > RowVector2d typedef Matrix< float , 1, 2 > RowVector2f typedef Matrix< int , 1, 2 > RowVector2i typedef Matrix< std::complex<double> , 1, 3 > RowVector3cd typedef Matrix< std::complex<float> , 1, 3 > RowVector3cf typedef Matrix< double , 1, 3 > RowVector3d typedef Matrix< float , 1, 3 > RowVector3f typedef Matrix< int , 1, 3 > RowVector3i typedef Matrix< std::complex<double> , 1, 4 > RowVector4cd typedef Matrix< std::complex<float> , 1, 4 > RowVector4cf typedef Matrix< double , 1, 4 > RowVector4d typedef Matrix< float , 1, 4 > RowVector4f typedef Matrix< int , 1, 4 > RowVector4i typedef Matrix< std::complex<double> , 1, Dynamic > RowVectorXcd typedef Matrix< std::complex<float> , 1, Dynamic > RowVectorXcf typedef Matrix<