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§
Sourcefn lu_decomposition(&self) -> Option<LUDecomposition>
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*USourcefn qr_decomposition(&self) -> Option<QRDecomposition>
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 = ISourcefn cholesky_decomposition(&self) -> Option<CholeskyDecomposition>
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
}Sourcefn svd_decomposition(&self) -> Option<SVDDecomposition>
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^TSourcefn is_positive_definite(&self) -> bool
fn is_positive_definite(&self) -> bool
Check if matrix is positive definite
Sourcefn condition_number(&self) -> Expression
fn condition_number(&self) -> Expression
Get condition number (ratio of largest to smallest singular value)
Implementors§
impl MatrixDecomposition for Matrix
Implementation of MatrixDecomposition trait for Matrix