Runtime-sized objects
matrix and vector: their extents live in the objects, the
dimension is read at run time and the runtime solver is resolved. The
other entry points are spelled exactly as on fixed-size objects.
Factorize, then substitute
One factorization, two right-hand sides.
\[\begin{split}
A = \left(\begin{array}{ccc|cc}
5 & 1 & 0 & 0 & 1 \\
1 & 6 & 1 & 0 & 0 \\
0 & 1 & 7 & 1 & 0 \\ \hline
0 & 0 & 1 & 8 & 1 \\
1 & 0 & 0 & 1 & 9
\end{array}\right), \quad
b_1 = \begin{pmatrix} 12 \\ 16 \\ 27 \\ 40 \\ 50 \end{pmatrix}, \quad
b_2 = \begin{pmatrix} 7 \\ 8 \\ 9 \\ 10 \\ 11 \end{pmatrix}, \quad
x_1 = \begin{pmatrix} 1 \\ 2 \\ 3 \\ 4 \\ 5 \end{pmatrix}, \quad
x_2 = \begin{pmatrix} 1 \\ 1 \\ 1 \\ 1 \\ 1 \end{pmatrix}
\end{split}\]
tfel::math::matrix<double> A = {
{5, 1, 0, 0, 1}, {1, 6, 1, 0, 0}, {0, 1, 7, 1, 0}, {0, 0, 1, 8, 1}, {1, 0, 0, 1, 9}};
const tfel::math::vector<double> b1 = {12, 16, 27, 40, 50}, b2 = {7, 8, 9, 10, 11};
tfel::math::vector<double> x1(5), x2(5);
tfel::math::vector<int> piv(5);
// the dimension is read from the objects at run time, the runtime solver is resolved
if (!tdls::factorize(A, piv)) return 1;
tdls::substitute(A, piv, b1, x1);
tdls::substitute(A, piv, b2, x2);
Solve in place
One buffer for the right-hand side and the solution.
\[\begin{split}
A = \left(\begin{array}{ccc|cc}
5 & 1 & 0 & 0 & 1 \\
1 & 6 & 1 & 0 & 0 \\
0 & 1 & 7 & 1 & 0 \\ \hline
0 & 0 & 1 & 8 & 1 \\
1 & 0 & 0 & 1 & 9
\end{array}\right), \quad b = \begin{pmatrix} 12 \\ 16 \\ 27 \\ 40 \\ 50 \end{pmatrix}, \quad x = \begin{pmatrix} 1 \\ 2 \\ 3 \\ 4 \\ 5 \end{pmatrix}
\end{split}\]
tfel::math::matrix<double> A = {
{5, 1, 0, 0, 1}, {1, 6, 1, 0, 0}, {0, 1, 7, 1, 0}, {0, 0, 1, 8, 1}, {1, 0, 0, 1, 9}};
tfel::math::vector<double> y = {12, 16, 27, 40, 50};
tfel::math::vector<int> piv(5);
// y holds b on entry and x on exit
const bool ok = tdls::solve_inplace(A, piv, y);
One canonical column
The right-hand side is a canonical vector, generated on the fly.
\[\begin{split}
A x = e_2, \quad A = \left(\begin{array}{ccc|cc}
5 & 1 & 0 & 0 & 1 \\
1 & 6 & 1 & 0 & 0 \\
0 & 1 & 7 & 1 & 0 \\ \hline
0 & 0 & 1 & 8 & 1 \\
1 & 0 & 0 & 1 & 9
\end{array}\right), \quad e_2 = \begin{pmatrix} 0 \\ 0 \\ 1 \\ 0 \\ 0 \end{pmatrix}
\end{split}\]
tfel::math::matrix<double> A = {
{5, 1, 0, 0, 1}, {1, 6, 1, 0, 0}, {0, 1, 7, 1, 0}, {0, 0, 1, 8, 1}, {1, 0, 0, 1, 9}};
tfel::math::vector<double> x(5);
tfel::math::vector<int> piv(5);
if (!tdls::factorize(A, piv)) return 1;
// x is column 2 of A^-1
tdls::substitute_canonical(A, piv, 2, x);