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
)
(
Slice!(Canonical, [2], IteratorA) a
,
Slice!(Contiguous, [1], lapackint*) ipiv
,
Slice!(kindB, n, IteratorB) b
,
char uplo = 'L'
)

Parameters

allowDestroy

flag to delete the source matrix.

a Slice!(Canonical, [2], IteratorA)

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

ipiv Slice!(Contiguous, [1], lapackint*)

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

b Slice!(kindB, n, IteratorB)

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

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!double(uniformVar(-100, 100), 4, 100);

auto LDL = A.ldlDecomp('L');
auto X = LDL.solve(B);

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

Meta