qrSolve

Solve the least squares problem: \min ||A * X - B|| Using the QR factorization: \A = Q * R computed by qrDecomp.

qrSolve
(
Flag!"allowDestroy" allowDestroy = No.allowDestroy
SliceKind kindB
size_t N
IteratorB
IteratorA
IteratorT
)
(
Slice!(IteratorA, 2, Canonical) a
,
Slice!(IteratorT) tau
,
Slice!(IteratorB, N, kindB) b
)

Parameters

allowDestroy

flag to delete the source matrix.

a Slice!(IteratorA, 2, Canonical)

detalis of the QR factorization of the original matrix as returned by qrDecomp.

tau Slice!(IteratorT)

details of the orhtogonal matrix Q.

b Slice!(IteratorB, N, kindB)

right hand side matrix.

Return Value

Type: auto

solution matrix.

Examples

import mir.ndslice;

auto A =
        [ 3,  1, -1,  2,
         -5,  1,  3, -4,
          2,  0,  1, -1,
          1, -5,  3, -3 ]
          .sliced(4, 4)
          .as!double.slice;

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

auto C = qrDecomp(A);
auto X = C.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