Eigen基本应用

来源:互联网 发布:网络营销策划方案例子 编辑:程序博客网 时间:2024/06/09 16:48

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

Eigen支持多种编译环境。

1、矩阵操作:#include <iostream>#include <Eigen/Dense>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  -12.5 1.5Here is the vector v:43
2、求解特征值和特征向量#include <iostream>#include <Eigen/Dense>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<Matrix2f> 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 22 3The eigenvalues of A are:-0.236  4.24Here'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

0 0
原创粉丝点击