nalgebra icon indicating copy to clipboard operation
nalgebra copied to clipboard

Added a simple LU decomposition

Open BogdanCiocea opened this issue 2 years ago • 1 comments

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 T that implements RealField from nalgebra.
  • Error Handling: Handles non-square matrices and singular matrices.
  • Matrix Printing: Method to print L and U matrices 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();

BogdanCiocea avatar Dec 18 '23 16:12 BogdanCiocea

How does this differ from e.g. Matrix::lu?

Ralith avatar Dec 20 '23 22:12 Ralith

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).

Andlon avatar Apr 03 '24 10:04 Andlon