Eigen基本应用

Eigen适用范围广,支持包括固定大小、任意大小的所有矩阵操作,甚至是稀疏矩阵;支持所有标准的数值类型,并且可以扩展为自定义的数值类型;支持多种矩阵分解及其几何特征的求解;它不支持的模块生态系统提供了许多专门的功能,如非线性优化,矩阵功能,多项式解算器,快速傅立叶变换等。

Eigen支持多种编译环境。

1、矩阵操作:
#include 
#include 
using namespace Eigen;
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << "Here is the matrix m:\n" << m << std::endl;
VectorXd v(2);
v(0) = 4;
v(1) = v(0) - 1;
std::cout << "Here is the vector v:\n" << v << std::endl;
}
输出为
Here is the matrix m: 
  3  -1
2.5 1.5
Here is the vector v:
4
3
2、求解特征值和特征向量
#include 
#include 
using namespace std;
using namespace Eigen;
int main()
{
Matrix2f A;
A << 1, 2, 2, 3;
cout << "Here is the matrix A:\n" << A << endl;
SelfAdjointEigenSolver eigensolver(A);
if (eigensolver.info() != Success) abort();
cout << "The eigenvalues of A are:\n" << eigensolver.eigenvalues() << endl;
cout << "Here's a matrix whose columns are eigenvectors of A \n"
<< "corresponding to these eigenvalues:\n"
<< eigensolver.eigenvectors() << endl;
}
输出为
Here is the matrix A:
1 2
2 3
The eigenvalues of A are:
-0.236  
4.24
Here's a matrix whose columns are eigenvectors of A corresponding to these eigenvalues:
-0.851 -0.526 
0.526 -0.851

原文链接:http://eigen.tuxfamily.org/index.php?title=Main_Page

                  http://baike.baidu.com/linkurl=2IZYOsGgCFEpJSF8HhYghkj6cn6suIBfuWvcjGcQAp8Rbo1nrvlBGrH0ZWdfxx9aTbY36rIzfE1gcVkTY8wg2K

你可能感兴趣的:(C++,Eigen)