简体   繁体   English

如何修复此 Eigen 矩阵求逆溢出错误?

[英]How to fix this Eigen matrix inversion overflow error?

#include "Eigen/Core"
#include <iostream>

using namespace std;
using namespace Eigen;

int main() {

    Matrix <float, 2, 2 > J;
    J << 0.0f, -1.0f, 1.0f, 0.0f;

    Matrix <float, 2, 2 > I;
    I << 1.0f, 0.0f, 0.0f, 1.0f;

    Matrix <float, 2, 2 > A;
    A = 20.0f * I + 30.0f * J;

    Matrix <float, 2, 2 > B;

    B = 10.0f * I + 25.0f * J;

    Matrix <float, 2, 2 > C;
    C = B;
    cout << C.inverse() << endl;

    return 0;
}

It gives an error which i couldn't fix.它给出了一个我无法修复的错误。 I don't know what is meant by "unsolved externals" here and if it is an overflow error how to fix it??我不知道这里“未解决的外部问题”是什么意思,如果是溢出错误如何解决?

If you look at the documentation of MatrixBase::inverse you'll see that it requires you to include Eigen/LU .如果您查看MatrixBase::inverse的文档,您会发现它要求您包含Eigen/LU Godbolt Demo: https://godbolt.org/z/ydfALn Godbolt 演示: https ://godbolt.org/z/ydfALn

If you just include Eigen/Core , you only get a forward-declaration of inverse , the compiler will assume it will be implemented elsewhere and the linker will fail, because it can't find the symbol.如果你只包含Eigen/Core ,你只会得到一个inverse的前向声明,编译器会假设它会在别处实现并且链接器会失败,因为它找不到符号。

Including Eigen/Dense would work as well, since that includes ia the Eigen/LU header.包括Eigen/Dense也可以,因为它包括 ia Eigen/LU标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM