我正在使用Eigen(与c ++一起使用的自由线性代数包)并试图反转一个小矩阵.遵循官方的Eigen文档后,我得到以下内容:
#include <iostream>
using namespace std;
#include <Eigen/LU>
#include <Eigen/Dense>
using namespace Eigen;
Matrix3d k = Matrix3d::Random();
cout << "Here is the matrix k:" << endl << k << endl;
cout << "Its inverse is:" << endl << k.inverse() << endl;
cout << "The product of the two (supposedly the identity) is:" << endl << k.inverse()*k << endl;
Run Code Online (Sandbox Code Playgroud)
这给了我正确的答案.但是,如果不是随机分配矩阵,如果我创建一个矩阵然后自己分配所有值,它会给我错误的反转.例如,以下代码将给出错误的反转.
Matrix3d m;
Matrix3d mi;
for (int i = 0; i < 3; ++ i)
for (int j = 0; j …Run Code Online (Sandbox Code Playgroud)