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.
Examples found in repository?
examples/basic_usage.rs (line 15)
3fn main() -> Result<(), use_linear::LinearError> {
4 let vector = Vector2::new(3.0, 4.0);
5 let basis = Matrix2::new(2.0, 1.0, 5.0, 3.0);
6 let rhs = Vector2::new(1.0, 2.0);
7
8 assert!((dot(vector, Vector2::new(-2.0, 1.0)) + 2.0).abs() < 1.0e-12);
9 assert!((vector.magnitude() - 5.0).abs() < 1.0e-12);
10 assert_eq!(
11 basis.mul_vector(Vector2::new(1.0, -1.0)),
12 Vector2::new(1.0, 2.0)
13 );
14 assert_eq!(basis * Matrix2::identity(), basis);
15 assert_eq!(solve_2x2(basis, rhs)?, Vector2::new(1.0, -1.0));
16
17 Ok(())
18}