pub fn solve_lu<T: Scalar>(
l: &Matrix<T>,
u: &Matrix<T>,
b: &Matrix<T>,
) -> Result<Matrix<T>>Expand description
Solve LU * x = b
Given factors L and U such that A = L * U, solves A * x = b
via forward and back substitution.
ยงExamples
use tensor4all_tcicore::{from_vec2d, matrixlu::{rrlu, solve_lu}};
let m = from_vec2d(vec![vec![2.0_f64, 1.0], vec![1.0, 3.0]]);
let lu = rrlu(&m, None).unwrap();
let l = lu.left(false);
let u = lu.right(false);
// b = [5, 10] => solve Ax = b in permuted coordinates
let b = from_vec2d(vec![
vec![m[[lu.row_permutation()[0], 0]] * 1.0 + m[[lu.row_permutation()[0], 1]] * 2.0],
vec![m[[lu.row_permutation()[1], 0]] * 1.0 + m[[lu.row_permutation()[1], 1]] * 2.0],
]);
let x = solve_lu(&l, &u, &b).unwrap();
// Solution in permuted col order
assert!((x[[lu.col_permutation().iter().position(|&c| c == 0).unwrap(), 0]] - 1.0).abs() < 1e-10);
assert!((x[[lu.col_permutation().iter().position(|&c| c == 1).unwrap(), 0]] - 2.0).abs() < 1e-10);