C++ : Math library that solve system of equations using back substitution algorithm
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.
Boost uBlas should work. At least if I understand your question correctly, you probably want to start by looking at lu_substitute()
and inplace_solve()
.
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
or strtrs
, depending on whether your data is in double- or single-precision.
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
For simplicity & lack of dependencies, I'd go for JAMA+TNT and use the LU
class for factorization and its solve()
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.
精彩评论