写在前面
Eigen是使用C++封装好的的一个矩阵运算库,可以很方便地实现各类矩阵运算,而且不用安装,只需要简单配置即可。
下载及配置
配置:
-
选择红框中的版本下载;
![](https://i-blog.csdnimg.cn/blog_migrate/dfe45f8a28896f992fd80e0209497473.png)
-
然后随便放在你想放的位置,解压;
-
打开VS项目,依次在属性管理器中打开 —> C/C++ —> 常规 —>添加依赖项 ——>然后把下载后解压的Eigen包的根目录添加进去,如图;
![](https://i-blog.csdnimg.cn/blog_migrate/342d8eff3091d8894e7c99b0fb47a20a.png)
-
添加后,即可使用。
测试代码
#include <iostream>
#include <Eigen\Dense>
using namespace std;
using namespace Eigen;
void 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");
}
![](https://i-blog.csdnimg.cn/blog_migrate/e1378a1342eadf277258605fd5660a1a.png)