我在下面尝试运行此代码,而逆执行此代码:
#include <iostream>
#include <Eigen/Dense>
using namespace std;
using namespace Eigen;
int main()
{
Matrix2d A;
A << 3, 5,
-7, 2;
cout << "Here is the matrix A:n" << A << endl;
cout << "The determinant of A is " << A.determinant() << endl;
cout << "The inverse of A is:n" << A.inverse() << endl;
}
但是我正在尝试倒数矩阵,这是可能的吗?
我正在尝试:
MatrixXd m(2,2);
m << 3, 5,
-7, 2;
cout << m.inverse() << endl;
这是错误:在此处输入图像描述
谢谢!
使用MatrixXd
与Matrix2d
相同的方式,除非您必须告诉它制作矩阵多大。这是VS 2013和Eigen 3.3.4
#include <iostream>
#include <EigenDense>
using namespace Eigen;
int main(int argc, char * argv[]){
Matrix2d A;
A << 3, 5, -7, 2;
std::cout << "Here is the matrix A:n" << A << 'n';
std::cout << "The determinant of A is:" << A.determinant() << 'n';
std::cout << "The inverse of A is:n" << A.inverse() << 'n';
MatrixXd B(5, 5);
B = MatrixXd::Random(5, 5);
std::cout << "Here is the matrix B:n" << B << 'n';
std::cout << "The determinant of B is:" << B.determinant() << 'n';
std::cout << "The inverse of B is:n" << B.inverse() << 'n';
return 0;
}
B
可以是您想要的任何大小。所有MatrixXd
都是Matrix<double, Dynamic, Dynamic>
的Typedef。你也可以用
Matrix<double, 5, 5> C = Matrix<double, 5, 5>::Random(5, 5);
如果您想要比这更好的解释,则必须包括您正在遇到的实际错误。