luSolve

Solves a system of linear equations \A * X = B, or \A**T * X = B with a general 'N x N' matrix 'A' using the LU factorization computed by luDecomp.

luSolve
(
Flag!"allowDestroy" allowDestroy = No.allowDestroy
SliceKind kindB
size_t N
IteratorB
IteratorLU
)
(
char trans
,
Slice!(IteratorLU, 2, Canonical) lut
,
Slice!(lapackint*) ipiv
,
Slice!(IteratorB, N, kindB) b
)

Parameters

allowDestroy

flag to delete the source matrix.

lut Slice!(IteratorLU, 2, Canonical)

factorization of matrix 'A', A = P * L * U.

ipiv Slice!(lapackint*)

the pivot indices from luDecomp.

b Slice!(IteratorB, N, kindB)

the right hand side matrix B.

trans char

specifies the form of the system of equations: 'N': A * X = B (No transpose) 'T': A**T * X = B (Transpose) 'C': A**T * X = B (Conjugate transpose = Transpose)

Return Value

Type: auto

Return solve of the system linear equations.

Examples

import mir.math;
import mir.ndslice;

auto A =
    [ 1,  4, -3,  5,  6,
     -2,  8,  5,  7,  8,
      3,  4,  7,  9,  1,
      2,  4,  6,  3,  2,
      6,  8,  3,  5,  2 ]
        .sliced(5, 5)
        .as!double.slice
        .canonical;

import mir.random.variable;
import mir.random.algorithm;
auto B = randomSlice(uniformVar(-100, 100), 5, 100);

auto LU = A.luDecomp();
auto X = LU.solve('N', B);

import mir.algorithm.iteration: equal;
assert(equal!((a, b) => fabs(a - b) < 1e-12)(mtimes(A, X), B));

Meta