pub struct SquareMatrix { /* private fields */ }Expand description
Row-major n×n dense matrix of f64. Maps to Foam::scalarSquareMatrix.
LU decomposition uses Crout’s algorithm with scaled partial pivoting,
matching Foam::LUDecompose(scalarSquareMatrix&, labelList&).
Implementations§
Source§impl SquareMatrix
impl SquareMatrix
Sourcepub fn get(&self, i: usize, j: usize) -> f64
pub fn get(&self, i: usize, j: usize) -> f64
Element in row i, column j (both 0-based, must be < n).
Sourcepub fn set(&mut self, i: usize, j: usize, v: f64)
pub fn set(&mut self, i: usize, j: usize, v: f64)
Set the element in row i, column j to v (0-based indices < n).
Sourcepub fn add(&mut self, i: usize, j: usize, v: f64)
pub fn add(&mut self, i: usize, j: usize, v: f64)
Add v to the element in row i, column j (0-based indices < n).
Sourcepub fn lu_decompose(&mut self) -> Vec<usize>
pub fn lu_decompose(&mut self) -> Vec<usize>
In-place LU decomposition with scaled partial pivoting.
After the call, self holds the combined LU factors (lower strictly
triangular, upper including diagonal). Returns the pivot-row indices.
Sourcepub fn lu_back_substitute(&self, pivot: &[usize], b: &mut Vec<f64>)
pub fn lu_back_substitute(&self, pivot: &[usize], b: &mut Vec<f64>)
Solve LU·x = b in-place (b is overwritten with the solution).
Must be called after lu_decompose. Matches
Foam::LUBacksubstitute(scalarSquareMatrix&, labelList&, List<scalar>&).
Sourcepub fn solve(&self, rhs: &[f64]) -> Result<Vec<f64>, MatrixError>
pub fn solve(&self, rhs: &[f64]) -> Result<Vec<f64>, MatrixError>
Convenience: decompose a copy and solve A·x = b.
Returns Err(MatrixError::Singular) if the matrix has an exactly-zero
pivot column (the LU sentinel f64::EPSILON was written to the diagonal).
Ill-conditioned but non-singular matrices are not detected; for those,
check the residual ‖Ax − b‖ manually.
Trait Implementations§
Source§impl Clone for SquareMatrix
impl Clone for SquareMatrix
Source§fn clone(&self) -> SquareMatrix
fn clone(&self) -> SquareMatrix
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more