Function russell_lab::solve_lin_sys[][src]

pub fn solve_lin_sys(b: &mut Vector, a: &mut Matrix) -> Result<(), &'static str>
Expand description

Solves a general linear system (real numbers)

For a general matrix a (square, symmetric, non-symmetric, dense, sparse), find x such that:

  a   ⋅  x  =  b
(m,m)   (m)   (m)

However, the right-hand-side will hold the solution:

b := a⁻¹⋅b == x

The solution is obtained via LU decomposition using Lapack dgesv routine.

Note

  1. The matrix a will be modified
  2. The right-hand-side b will contain the solution x
// import
use russell_lab::*;

// set matrix and right-hand side
let mut a = Matrix::from(&[
    [1.0,  3.0, -2.0],
    [3.0,  5.0,  6.0],
    [2.0,  4.0,  3.0],
]);
let mut b = Vector::from(&[5.0, 7.0, 8.0]);

// solve linear system b := a⁻¹⋅b
solve_lin_sys(&mut b, &mut a)?;

// check
let x_correct = "┌         ┐\n\
                 │ -15.000 │\n\
                 │   8.000 │\n\
                 │   2.000 │\n\
                 └         ┘";
assert_eq!(format!("{:.3}", b), x_correct);