C++ :使用回代算法求解方程组的数学库
如果我有这个:
A * f = g;
A: upper triangular matrix (n x n)
f: (n x 1)
g: (n x 1)
需要使用回代算法求解 f
。我想说,自己写一个并不难,但是哦,好吧,如果有一个图书馆,那为什么不呢。
If I have this:
A * f = g;
A: upper triangular matrix (n x n)
f: (n x 1)
g: (n x 1)
Need to solve for f
using back substitution algorithm. I would say that it not really that hard to write one myself, but oh well, if there is a library out there, then why not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Boost uBlas 应该可以工作。至少如果我正确理解你的问题,你可能想首先查看
lu_substitute()
和inplace_solve()
。Boost uBlas should work. At least if I understand your question correctly, you probably want to start by looking at
lu_substitute()
andinplace_solve()
.使用LAPACK。它已经安装在许多系统上,并且对于没有它的系统有许多可用的实现。
具体来说,您想要的例程是
dtrtrs
或strtrs
,具体取决于您的数据是双精度还是单精度。Use the LAPACK. It's already installed on many systems, and there are many implementations available for systems that don't have it.
Specifically, the routine you want is
dtrtrs
orstrtrs
, depending on whether your data is in double- or single-precision.是其中之一吗?我以前没有听说过用“回代”求解线性方程组。为什么一定要回代呢?
http://eigen.tuxfamily.org/dox/TutorialAdvancedLinearAlgebra.html
Is it one of these? I haven't heard of solving systems of linear equations with "back substitution" before. Why does it have to be back substitution?
http://eigen.tuxfamily.org/dox/TutorialAdvancedLinearAlgebra.html
为了简单起见缺乏依赖项,我会选择 JAMA+TNT 并使用
LU
类 用于分解及其solve()方法。似乎没有一种方法可以使用预先存在的上三角矩阵来初始化 LU(LU 的构造函数不做任何假设,只是开始分解),但我认为您可以按原样使用它,并承受性能影响冗余因式分解,或者只是采用求解方法并根据您的需要进行调整。
For simplicity & lack of dependencies, I'd go for JAMA+TNT and use the
LU
class for factorization and itssolve()
method. There doesn't appear to be a way you can initialize LU with a pre-existing upper triangular matrix (LU's constructor makes no assumptions and just starts factoring) but I would think you could either use it as is, and live with the performance hit of the redundant factoring, or just take solve method and adapt it to your needs.