packages

linalg::factor::cholesky

On this page

Cholesky (A = L L^H) and the square-root-free LDL^H, both row by row (left-looking: each entry is one inner product of rows already done), reading only the lower triangle. Cholesky is backward stable for any positive definite matrix; O(n^3/3).

Structs

CholeskySource

pub struct Cholesky<T>

A = L L^H of a Hermitian (real: symmetric) positive definite matrix, L lower triangular with a positive diagonal. Only the lower triangle of A is read.

nabi
use core::array::{Matrix, Vector};

let a: Matrix<f64> = [[4, 2], [2, 5]];
let c = try linalg::cholesky(a);
assert(c.l()[1, 0] == 1.0 && c.l()[1, 1] == 2.0);
let b: Vector<f64> = [6, 7];
assert(try c.solve(b) == Vector::<f64>::from([1.0, 1.0]));
  • pub fn l(self) -> Matrix<T>§

    Source

    The lower factor L.

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

    Source

    x with A x = b.

  • pub fn inv(self) throws (LinalgError) -> Matrix<T>§

    Source

    A^-1.

  • pub fn det(self) -> T§

    Source

    det(A), the squared product of L's diagonal.

  • pub fn logdet(self) -> T::Real§

    Source

    ln det(A), without the overflow of det for large matrices.

LdltSource

pub struct Ldlt<T>

A = L D L^H without pivoting: L unit lower triangular, D real diagonal. Needs nonzero leading minors (true for positive definite and quasi-definite matrices); for a general symmetric indefinite matrix use lu, which pivots. Only the lower triangle is read.

nabi
use core::array::Matrix;

let a: Matrix<f64> = [[4, 2], [2, -1]];
let f = try linalg::ldlt(a);
assert(f.d()[0] == 4.0 && f.d()[1] == -2.0);
  • pub fn l(self) -> Matrix<T>§

    Source

    The unit lower factor L.

  • pub fn d(self) -> Vector<T::Real>§

    Source

    The diagonal of D.

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

    Source

    x with A x = b.

  • pub fn det(self) -> T§

    Source

    det(A), the product of D.