Skip to main content

solve_2x2

Function solve_2x2 

Source
pub fn solve_2x2(matrix: Matrix2, rhs: Vector2) -> Result<Vector2, LinearError>
Expand description

Solves matrix * x = rhs for x.

§Errors

Returns LinearError::SingularMatrix when the determinant is zero or non-finite.

§Examples

use use_linear::solve_2x2;
use use_matrix::Matrix2;
use use_vector::Vector2;

let matrix = Matrix2::new(2.0, 1.0, 5.0, 3.0);
let rhs = Vector2::new(1.0, 2.0);

assert_eq!(solve_2x2(matrix, rhs)?, Vector2::new(1.0, -1.0));
Examples found in repository?
examples/basic_usage.rs (line 9)
5fn main() -> Result<(), use_linear::LinearError> {
6    let basis = Matrix2::new(2.0, 1.0, 5.0, 3.0);
7    let rhs = Vector2::new(1.0, 2.0);
8
9    assert_eq!(solve_2x2(basis, rhs)?, Vector2::new(1.0, -1.0));
10
11    Ok(())
12}