- 先在官网Eigen
http://eigen.tuxfamily.org/index.php?title=Main_Page下载C++ Eigen库的zip压缩包,我选择的是3.3.9版本
- 然后在vs2022的项目--VC++目录--包含目录中导入解压的zip文件
- 然后输入以下代码即可完成四则(加减乘除)运算。
#include <iostream> #include <Eigen/Dense> using namespace Eigen; using namespace std; int main() { // 创建两个3x3的矩阵 Matrix3d A; Matrix3d B; // 给矩阵A和B赋值 A << 1, 2, 3, 4, 5, 6, 7, 8, 9; B << 1, 0, 0, 0, 1, 0, 0, 0, 1; // 矩阵加法 Matrix3d C = A + B; cout << "矩阵加法 A + B =\n" << C << endl; // 矩阵减法 Matrix3d D = A - B; cout << "矩阵减法 A - B =\n" << D << endl; // 矩阵乘法 Matrix3d E = A * B; cout << "矩阵乘法 A * B =\n" << E << endl; // 矩阵除法(实际上是乘以其逆矩阵) Matrix3d F = A.inverse() * B; cout << "矩阵除法 A / B =\n" << F << endl; return 0; }
08-09
8万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-17
8934
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-09
2525
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-22
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交