Module ndarray_linalg::solve
source · Expand description
Solve systems of linear equations and invert matrices
§Examples
Solve A * x = b
:
use ndarray::prelude::*;
use ndarray_linalg::Solve;
let a: Array2<f64> = array![[3., 2., -1.], [2., -2., 4.], [-2., 1., -2.]];
let b: Array1<f64> = array![1., -2., 0.];
let x = a.solve_into(b).unwrap();
assert!(x.abs_diff_eq(&array![1., -2., -2.], 1e-9));
There are also special functions for solving A^T * x = b
and
A^H * x = b
.
If you are solving multiple systems of linear equations with the same
coefficient matrix A
, it’s faster to compute the LU factorization once at
the beginning than solving directly using A
:
use ndarray::prelude::*;
use ndarray_linalg::*;
/// Use fixed algorithm and seed of PRNG for reproducible test
let mut rng = rand_pcg::Mcg128Xsl64::new(0xcafef00dd15ea5e5);
let a: Array2<f64> = random_using((3, 3), &mut rng);
let f = a.factorize_into().unwrap(); // LU factorize A (A is consumed)
for _ in 0..10 {
let b: Array1<f64> = random_using(3, &mut rng);
let x = f.solve_into(b).unwrap(); // Solve A * x = b using factorized L, U
}
Structs§
- Represents the LU factorization of a matrix
A
asA = P*L*U
.
Enums§
Traits§
- An interface for calculating determinants of matrix refs.
- An interface for calculating determinants of matrices.
- An interface for computing LU factorizations of matrix refs.
- An interface for computing LU factorizations of matrices.
- An interface for inverting matrix refs.
- An interface for inverting matrices.
- An interface for estimating the reciprocal condition number of matrix refs.
- An interface for estimating the reciprocal condition number of matrices.
- An interface for solving systems of linear equations.