Added a simple LU decomposition
Add LU Decomposition for Square Matrices Using nalgebra
Overview
This pull request introduces an implementation of LU Decomposition for square matrices using the nalgebra library in Rust. LU Decomposition is crucial in numerical linear algebra for solving linear equations, inverting matrices, and computing determinants.
Features
-
LU Decomposition Struct: Stores the lower (
L) and upper (U) triangular matrices. -
Generic Implementation: Works with any type
Tthat implementsRealFieldfrom nalgebra. - Error Handling: Handles non-square matrices and singular matrices.
-
Matrix Printing: Method to print
LandUmatrices for verification. - Comprehensive Testing: Includes tests for various scenarios including singular and non-square matrices.
Usage
The LuDecomposition::decompose method performs the decomposition, returning L and U matrices within LuDecomposition struct.
Example
let matrix = DMatrix::from_row_slice(3, 3, &[2.0, 3.0, 1.0, 4.0, 1.0, -1.0, -1.0, 3.0, 2.0]);
let lu = LuDecomposition::decompose(&matrix).unwrap();
lu.print_matrices();
How does this differ from e.g. Matrix::lu?
Thanks for putting in the effort for this, but as pointed out by @Ralith, nalgebra already has several variants of the LU decomposition. I'm therefore going to close this PR, but feel free to let us know if you feel there is something inadequate about the existing LU implementation(s).