【问题标题】:Using Cramers rule with the Eigen library [closed]将 Cramers 规则与 Eigen 库一起使用 [关闭]
【发布时间】:2015-04-01 12:34:32
【问题描述】:

我正在使用 Eigen 线性代数库,我想求解一个 3x3 矩阵。过去我使用过克莱默法则。有谁知道我是否可以在 Eigen 中使用 cramer 规则,或者我需要自己编程吗?

我正在使用 C++ 11 和 Linux。我不能使用任何其他外部库,例如 BOOST 等。

【问题讨论】:

    标签: c++ matrix linear-algebra eigen


    【解决方案1】:

    是的。您可以使用eigen。看看这里的文档

    http://eigen.tuxfamily.org/dox/group__TutorialLinearAlgebra.html

    给出的例子非常简短:

    #include <iostream>
    #include <Eigen/Dense>
    using namespace std;
    using namespace Eigen;
    int main()
    {
       Matrix3f A;
       Vector3f b;
       A << 1,2,3,  4,5,6,  7,8,10;
       b << 3, 3, 4;
       cout << "Here is the matrix A:\n" << A << endl;
       cout << "Here is the vector b:\n" << b << endl;
       Vector3f x = A.colPivHouseholderQr().solve(b);
       cout << "The solution is:\n" << x << endl;
    }
    

    输出:

    Here is the matrix A:
     1  2  3
     4  5  6
     7  8 10
    Here is the vector b:
    3
    3
    4
    The solution is:
    -2
     1
     1
    

    几乎可以保证比使用克莱默规则的手工求解器工作得更快。

    【讨论】:

    • 是的,我错过了。谢谢,我会检查一下。
    • Np。 PS:为了将来参考,最好将问题留待至少一段时间(例如一两天)。您(以及后来偶然发现的人)可能会通过这种方式得到更好的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    相关资源
    最近更新 更多