choleskySolve

Solves a system of linear equations A * X = B with a symmetric matrix A using the Cholesky factorization: \A = U**T * U or \A = L * L**T computed by choleskyDecomp.

choleskySolve
(
Flag!"allowDestroy" allowDestroy = No.allowDestroy
SliceKind kindB
size_t N
IteratorB
IteratorC
)
(
char uplo
,
Slice!(IteratorC, 2, Canonical) c
,
Slice!(IteratorB, N, kindB) b
)

Parameters

allowDestroy

flag to delete the source matrix.

c Slice!(IteratorC, 2, Canonical)

the triangular factor 'U' or 'L' from the Cholesky factorization

b Slice!(IteratorB, N, kindB)

the right hand side matrix.

uplo char

'U': Upper triangle of A is stored; 'L': Lower triangle of A is stored.

Return Value

Type: auto

The solution matrix X.

Examples

import mir.ndslice.slice: sliced;
import mir.ndslice.topology: as;
import std.typecons: Flag, Yes;

auto A =
        [ 1.0,  1,  3,
          1  ,  5,  5,
          3  ,  5, 19 ].sliced(3, 3);

auto B = [ 10.0,  157,  80 ].sliced;
auto C_ = B.dup.sliced(3, 1);

auto C = choleskyDecomp('U', A);
auto X = choleskySolve!(Yes.allowDestroy)(C.uplo, C.matrix, B);

import mir.math.common: approxEqual;
import mir.algorithm.iteration: equal;
alias appr = equal!((a, b) => approxEqual(a, b, 1e-5, 1e-5));
assert(appr(mtimes(A, X), C_));

Meta