ldlSolve

Solves a system of linear equations \A * X = B with symmetric matrix 'A' using the factorization \A = U * D * U**T, or \A = L * D * L**T computed by ldlDecomp.

ldlSolve
(
Flag!"allowDestroy" allowDestroy = No.allowDestroy
SliceKind kindB
size_t N
IteratorB
IteratorA
)
(
char uplo
,
Slice!(IteratorA, 2, Canonical) a
,
Slice!(lapackint*) ipiv
,
Slice!(IteratorB, N, kindB) b
)

Parameters

allowDestroy

flag to delete the source matrix.

a Slice!(IteratorA, 2, Canonical)

'LD' or 'UD' matrix computed by ldlDecomp.

ipiv Slice!(lapackint*)

details of the interchanges and the block structure of D as determined by ldlDecomp.

b Slice!(IteratorB, N, kindB)

the right hand side matrix.

uplo char

specifies whether the details of the factorization are stored as an upper or lower triangular matrix: 'U': Upper triangular, form is \A = U * D * U**T; 'L': Lower triangular, form is \A = L * D * L**T.

Return Value

Type: auto

The solution matrix.

Examples

import mir.ndslice;

auto A =
    [ 2.07,  3.87,  4.20, -1.15,
      3.87, -0.21,  1.87,  0.63,
      4.20,  1.87,  1.15,  2.06,
     -1.15,  0.63,  2.06, -1.81 ]
        .sliced(4, 4)
        .as!double.slice
        .canonical;

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

auto LDL = ldlDecomp('L', A);
auto X = LDL.solve(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), B));

Meta