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
)
(
Slice!(Canonical, [2], IteratorC) c
,
Slice!(kindB, n, IteratorB) b
,
char uplo
)

Parameters

allowDestroy

flag to delete the source matrix.

c Slice!(Canonical, [2], IteratorC)

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

b Slice!(kindB, n, IteratorB)

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

auto A =
       [ 25, 15, -5,
         15, 18,  0,
         -5,  0, 11 ]
         .sliced(3, 3)
         .as!double.slice;

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

auto C = A.choleskyDecomp('L');
auto X = C.solve(B);

import std.math: approxEqual;
import mir.ndslice.algorithm: equal;
assert(equal!approxEqual(mtimes(A, X), B));

Meta