solve_triangular

Function solve_triangular 

Source
pub fn solve_triangular<F>(
    a: &ArrayView2<'_, F>,
    b: &ArrayView1<'_, F>,
    lower: bool,
    unit_diagonal: bool,
) -> LinalgResult<Array1<F>>
where F: Float + NumAssign + Sum + Send + Sync + ScalarOperand + 'static,
Expand description

Solve a linear system with a lower or upper triangular coefficient matrix.

§Arguments

  • a - Triangular coefficient matrix
  • b - Ordinate or “dependent variable” values
  • lower - If true, the matrix is lower triangular, if false, upper triangular
  • unit_diagonal - If true, the diagonal elements of a are assumed to be 1

§Returns

  • Solution vector x

§Examples

use scirs2_core::ndarray::{array, ScalarOperand};
use scirs2_linalg::solve_triangular;

// Lower triangular system
let a = array![[1.0_f64, 0.0], [2.0, 3.0]];
let b = array![2.0_f64, 8.0];
let x = solve_triangular(&a.view(), &b.view(), true, false).unwrap();
assert!((x[0] - 2.0).abs() < 1e-10);
assert!((x[1] - 4.0/3.0).abs() < 1e-10);