packages

linalg::factor::qr

On this page

Householder QR (LAPACK's xGEQRF / xGEQP3 conventions): step k turns column k below the diagonal into zeros with H_k = I - tau v v^H, v[k] = 1, keeping v below R. Column pivoting moves the column of largest remaining norm to the front first; the norms are downdated and recomputed when cancellation makes them unreliable. Backward stable; O(2mn^2 - 2n^3/3).

Structs

QrSource

pub struct Qr<T>

A P = Q R of an m x n matrix: Q unitary (orthogonal for real input), R upper triangular, P a column permutation (the identity unless built with qr_pivoted).

nabi
use core::array::Matrix;

let a: Matrix<f64> = [[3, 1], [4, 2]];
let f = try linalg::qr(a);
let r = f.r();
assert((r[0, 0].abs() - 5.0).abs() < 1e-12);
  • pub fn q(self) -> Matrix<T>§

    Source

    The thin Q: m x min(m, n), orthonormal columns.

  • pub fn q_full(self) -> Matrix<T>§

    Source

    The full Q: m x m, unitary.

  • pub fn r(self) -> Matrix<T>§

    Source

    R: min(m, n) x n, upper triangular. With pivoting its diagonal falls in magnitude.

  • pub fn perm(self) -> List<usize>§

    Source

    The column order: column j of A P is column perm()[j] of A.

  • pub fn solve<B: Rhs<T>>(self, b: B) throws (LinalgError) -> B§

    Source

    The least-squares solution of A x = b (the exact one when A is square), for m >= n and full column rank. Throws Singular when a diagonal entry of R is zero; use lstsq for rank-deficient A.