1 下载
git clone https://gitlab.com/libeigen/eigen.git
2 编译安装
cd eigen
mkdir build && cd build
cmake ..
make install
该方法默认安装在:
/usr/local/include/eigen3 /usr/local/share/eigen3
3 测试
将下面代码命名为testEigen.cpp:
#include <iostream>
#include <eigen3/Eigen/Dense>
using namespace std;
using namespace Eigen;
int main()
{
Matrix2d a;
a << 1, 2,
3, 4;
MatrixXd b(2, 2);
b << 2, 3,
1, 4;
cout << "a + b =\n" << a + b << endl;
cout << "a - b =\n" << a - b << endl;
cout << "Doing a += b;" << endl;
a += b;
cout << "Now a =\n" << a << endl;
cout << "a^T= " << a.transpose() << endl;
cout << "a*b= " << a*b << endl;
Vector3d v(1, 2, 3);
Vector3d w(1, 0, 0);
cout << "-v + w - v =\n" << -v + w - v << endl;
cout << v << endl;
cout << v.transpose() << endl;
system("pause");
return 0;
}
编译测试:
g++ testEigen.cpp -o a.out && ./a.out

本文档介绍了如何下载、编译并安装开源矩阵运算库Eigen,以及如何编写和测试简单的Eigen代码示例。通过克隆GitLab上的Eigen仓库,使用CMake构建并安装到本地,然后编写一个C++程序来展示Eigen的功能,包括矩阵加减、乘法、转置等操作。
842

被折叠的 条评论
为什么被折叠?



