pub struct FullPivLu<T> { /* private fields */ }
Expand description
LU decomposition with complete pivoting.
For any square matrix A, there exist two permutation matrices
P
and Q
, a lower triangular matrix L
and an upper triangular
matrix U
such that
PAQ = LU.
Unlike the LU decomposition computed with partial pivoting, this decomposition is stable for singular matrices. It is also a rank- revealing decomposition.
See PartialPivLu for applications of LU decompositions in general.
Implementations
sourceimpl<T> FullPivLu<T>where
T: Any + Float,
impl<T> FullPivLu<T>where
T: Any + Float,
sourcepub fn solve(&self, b: Vector<T>) -> Result<Vector<T>, Error>
pub fn solve(&self, b: Vector<T>) -> Result<Vector<T>, Error>
Solves the linear system Ax = b
.
Here, A
is the decomposed matrix satisfying
PAQ = LU
. Note that this method is particularly
well suited to solving multiple such linear systems
involving the same A
but different b
.
Errors
If the matrix is very ill-conditioned, the function might fail to obtain the solution to the system.
Panics
The right-hand side vector b
must have compatible size.
Examples
let x = Matrix::identity(4);
let lu = FullPivLu::decompose(x).unwrap();
let b = vector![3.0, 4.0, 2.0, 1.0];
let y = lu.solve(b)
.expect("Matrix is invertible.");
assert_vector_eq!(y, vector![3.0, 4.0, 2.0, 1.0], comp = float);
sourcepub fn inverse(&self) -> Result<Matrix<T>, Error>
pub fn inverse(&self) -> Result<Matrix<T>, Error>
Computes the inverse of the matrix which this LUP decomposition represents.
Errors
The inversion might fail if the matrix is very ill-conditioned. The inversion fails if the matrix is not invertible.
sourcepub fn det(&self) -> T
pub fn det(&self) -> T
Computes the determinant of the decomposed matrix.
Empty matrices are considered to have a determinant of 1.0.
Panics
If the underlying matrix is non-square.
sourcepub fn rank(&self) -> usize
pub fn rank(&self) -> usize
Computes the rank of the decomposed matrix.
Examples
let x = matrix![1.0, 2.0, 3.0;
4.0, 5.0, 6.0;
5.0, 7.0, 9.0];
let lu = FullPivLu::decompose(x).unwrap();
assert_eq!(lu.rank(), 2);
sourcepub fn is_invertible(&self) -> bool
pub fn is_invertible(&self) -> bool
Returns whether the matrix is invertible.
Empty matrices are considered to be invertible for the sake of this function.
Examples
let x = Matrix::<f64>::identity(4);
let lu = FullPivLu::decompose(x).unwrap();
assert!(lu.is_invertible());
let y = matrix![1.0, 2.0, 3.0;
4.0, 5.0, 6.0;
5.0, 7.0, 9.0];
let lu = FullPivLu::decompose(y).unwrap();
assert!(!lu.is_invertible());