pub struct Lu<const D: usize> { /* private fields */ }Expand description
LU decomposition (PA = LU) with partial pivoting.
Lu<0> represents the empty factorization. Its determinant is the empty
product 1.0, and solving against Vector<0> returns Vector<0>.
Numerical solves and determinants remain subject to binary64 rounding and
matrix conditioning; this type does not provide a certified error bound.
Implementations§
Source§impl<const D: usize> Lu<D>
impl<const D: usize> Lu<D>
Sourcepub const fn solve(&self, b: Vector<D>) -> Result<Vector<D>, LaError>
pub const fn solve(&self, b: Vector<D>) -> Result<Vector<D>, LaError>
Solve A x = b using this LU factorization.
Vector is finite by construction, so this method only checks computed
substitution overflows. It performs floating-point forward/back
substitution and does not provide a certified absolute rounding-error
bound for the returned solution.
§Examples
use la_stack::prelude::*;
let a = Matrix::<2>::try_from_rows([[1.0, 2.0], [3.0, 4.0]])?;
let lu = a.lu(DEFAULT_SINGULAR_TOL)?;
let b = Vector::<2>::try_new([5.0, 11.0])?;
let x = lu.solve(b)?.into_array();
assert!((x[0] - 1.0).abs() <= 1e-12);
assert!((x[1] - 2.0).abs() <= 1e-12);§Errors
Returns LaError::NonFinite if a computed substitution intermediate
overflows to NaN or infinity.
Sourcepub const fn det(&self) -> Result<f64, LaError>
pub const fn det(&self) -> Result<f64, LaError>
Determinant of the original matrix.
§Examples
use la_stack::prelude::*;
let a = Matrix::<2>::try_from_rows([[1.0, 2.0], [3.0, 4.0]])?;
let lu = a.lu(DEFAULT_SINGULAR_TOL)?;
let det = lu.det()?;
assert!((det - (-2.0)).abs() <= 1e-12);Diagonal pivots are multiplied directly while each non-zero running
product remains finite and normal. If direct accumulation detects range
loss, all pivots are recomputed with power-of-two scaling before a
premature overflow or underflow can affect the returned determinant.
The final product is rounded to f64; a non-zero magnitude below the
binary64 range may round to zero. No certified absolute error bound is
provided.
§Errors
Returns LaError::NonFinite if the final scaled determinant cannot be
represented as a finite f64.