Module ndarray_linalg::solve[][src]

Solve systems of linear equations and invert matrices

Examples

Solve A * x = b:

#[macro_use]
extern crate ndarray;
extern crate ndarray_linalg;

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.all_close(&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::*;

let a: Array2<f64> = random((3, 3));
let f = a.factorize_into().unwrap(); // LU factorize A (A is consumed)
for _ in 0..10 {
    let b: Array1<f64> = random(3);
    let x = f.solve_into(b).unwrap(); // Solve A * x = b using factorized L, U
}

Re-exports

pub use lapack_traits::Pivot;
pub use lapack_traits::Transpose;

Structs

LUFactorized

Represents the LU factorization of a matrix A as A = P*L*U.

Traits

Determinant

An interface for calculating determinants of matrix refs.

DeterminantInto

An interface for calculating determinants of matrices.

Factorize

An interface for computing LU factorizations of matrix refs.

FactorizeInto

An interface for computing LU factorizations of matrices.

Inverse

An interface for inverting matrix refs.

InverseInto

An interface for inverting matrices.

ReciprocalConditionNum

An interface for estimating the reciprocal condition number of matrix refs.

ReciprocalConditionNumInto

An interface for estimating the reciprocal condition number of matrices.

Solve

An interface for solving systems of linear equations.