1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
use crate::algebra::{ abstr::{Field, Scalar}, linear::{matrix::lu::LUDec, matrix::Inverse, Matrix}, }; impl<T> Inverse<T> for Matrix<T> where T: Field + Scalar { /// Inverse Matrix /// /// # Example /// /// ``` /// use mathru::algebra::linear::{matrix::*, Matrix}; /// /// let a: Matrix<f64> = Matrix::new(2, 2, vec![1.0, 0.0, 3.0, -7.0]); /// let b_inv: Matrix<f64> = a.inv().unwrap(); /// ``` fn inv(self: &Self) -> Result<Matrix<T>, ()> { return self.inv_r(); } } impl<T> Matrix<T> where T: Field + Scalar { pub fn inv_r(self: &Self) -> Result<Matrix<T>, ()> { let lu_dec: LUDec<T> = self.dec_lu()?; return lu_dec.inv(); } }