赞
踩
常见的矩阵运算包括:转置、逆矩阵、行列式、矩阵加减、乘积,示例如下:
- #include<iostream>
- #include<Eigen\dense>
- using namespace std;
- using namespace Eigen;
-
- void main()
- {
- MatrixXd m1(3, 3), m2(3, 3);
- m1 << 1, 2, 3, 4, 6, 8, 7, 9, 9;
- m2 << 1, 2, 3, 4, 6, 8, 7, 9, 9;
-
- MatrixXd m(3, 3);
- //矩阵相加
- m = m1 + m2;
- cout << "m1矩阵为: "<< endl << m1 << endl;
- cout << "m2矩阵为:" << endl << m2 << endl;
- cout << "m1+m2=" << endl << m << endl << endl;
-
- //矩阵的转置
- cout << "m1的转置为:" << endl << m1.transpose() << endl << endl;
-
- //矩阵的逆
- cout << "m1的逆矩阵为" << endl << m1.inverse() << endl << endl;
-
- //矩阵的行列式为
- cout << "m1的行列式为:" << endl << m1.determinant() << endl << endl;
-
- //矩阵相乘
- cout << "m1*m2为:" << endl << m1*m2 << endl << endl;
-
-
- //特征值与特征向量
- EigenSolver<MatrixXd> eigensolver(m1);
- if (eigensolver.info() != Success)
- {
- abort();
- }
-
- cout << "特征值:" << endl << eigensolver.eigenvalues() << endl << endl;
- cout << "特征向量" << endl << eigensolver.eigenvectors() << endl << endl;
- system("pause");
-
- }
-
右边截图是MATLAB计算结果。
注意:在使用adjointeigensolver解算特征值与特征向量时,与MATLAB解算的结果是不一样的!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。