【发布时间】:2015-04-01 12:34:32
【问题描述】:
我正在使用 Eigen 线性代数库,我想求解一个 3x3 矩阵。过去我使用过克莱默法则。有谁知道我是否可以在 Eigen 中使用 cramer 规则,或者我需要自己编程吗?
我正在使用 C++ 11 和 Linux。我不能使用任何其他外部库,例如 BOOST 等。
【问题讨论】:
标签: c++ matrix linear-algebra eigen
我正在使用 Eigen 线性代数库,我想求解一个 3x3 矩阵。过去我使用过克莱默法则。有谁知道我是否可以在 Eigen 中使用 cramer 规则,或者我需要自己编程吗?
我正在使用 C++ 11 和 Linux。我不能使用任何其他外部库,例如 BOOST 等。
【问题讨论】:
标签: c++ matrix linear-algebra eigen
是的。您可以使用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
几乎可以保证比使用克莱默规则的手工求解器工作得更快。
【讨论】: