Skip to main content

MatrixDecomposition

Trait MatrixDecomposition 

Source
pub trait MatrixDecomposition {
    // Required methods
    fn lu_decomposition(&self) -> Option<LUDecomposition>;
    fn qr_decomposition(&self) -> Option<QRDecomposition>;
    fn cholesky_decomposition(&self) -> Option<CholeskyDecomposition>;
    fn svd_decomposition(&self) -> Option<SVDDecomposition>;
    fn rank(&self) -> usize;
    fn is_positive_definite(&self) -> bool;
    fn condition_number(&self) -> Expression;
}
Expand description

Matrix decomposition operations trait

This trait provides a unified interface for all matrix decomposition methods. Each method returns an Option to handle cases where decomposition is not possible.

Required Methods§

Source

fn lu_decomposition(&self) -> Option<LUDecomposition>

Perform LU decomposition with partial pivoting

Decomposes matrix A into PA = LU where:

  • P is a permutation matrix
  • L is lower triangular with 1s on diagonal
  • U is upper triangular
§Examples
use mathhook_core::matrices::{Matrix, MatrixDecomposition};
use mathhook_core::Expression;

let matrix = Matrix::from_arrays([
    [2, 1, 1],
    [4, 3, 3],
    [8, 7, 9]
]);

let lu = matrix.lu_decomposition().unwrap();
// Verify: P*A = L*U
Source

fn qr_decomposition(&self) -> Option<QRDecomposition>

Perform QR decomposition using Gram-Schmidt process

Decomposes matrix A into A = QR where:

  • Q is orthogonal (Q^T * Q = I)
  • R is upper triangular
§Examples
use mathhook_core::matrices::{Matrix, MatrixDecomposition};

let matrix = Matrix::from_arrays([
    [1, 1, 0],
    [1, 0, 1],
    [0, 1, 1]
]);

let qr = matrix.qr_decomposition().unwrap();
// Verify: A = Q*R and Q^T*Q = I
Source

fn cholesky_decomposition(&self) -> Option<CholeskyDecomposition>

Perform Cholesky decomposition for positive definite matrices

Decomposes symmetric positive definite matrix A into A = LL^T where:

  • L is lower triangular with positive diagonal elements
§Examples
use mathhook_core::matrices::{Matrix, MatrixDecomposition};

let matrix = Matrix::from_arrays([
    [4, 2, 1],
    [2, 3, 0],
    [1, 0, 2]
]);

if let Some(chol) = matrix.cholesky_decomposition() {
    // Verify: A = L*L^T
}
Source

fn svd_decomposition(&self) -> Option<SVDDecomposition>

Perform Singular Value Decomposition

Decomposes matrix A into A = UΣV^T where:

  • U contains left singular vectors (orthogonal)
  • Σ contains singular values (diagonal, non-negative)
  • V^T contains right singular vectors (orthogonal)
§Examples
use mathhook_core::matrices::{Matrix, MatrixDecomposition};

let matrix = Matrix::from_arrays([
    [1, 2],
    [3, 4],
    [5, 6]
]);

let svd = matrix.svd_decomposition().unwrap();
// Verify: A = U*Σ*V^T
Source

fn rank(&self) -> usize

Get matrix rank using SVD

Source

fn is_positive_definite(&self) -> bool

Check if matrix is positive definite

Source

fn condition_number(&self) -> Expression

Get condition number (ratio of largest to smallest singular value)

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl MatrixDecomposition for Matrix

Implementation of MatrixDecomposition trait for Matrix