implement minor for matrix3x3

This commit is contained in:
Bill Thiede 2021-07-01 21:29:58 -07:00
parent a69e404817
commit f5d79908f6

View File

@ -81,6 +81,20 @@ impl Matrix3x3 {
let m = [[rows[0][0], rows[0][1]], [rows[1][0], rows[1][1]]];
Matrix2x2 { m }
}
///
/// # Examples
/// ```
/// use rtchallenge::matrices::{Matrix2x2, Matrix3x3};
///
/// let a = Matrix3x3::new([3., 5., 0.], [2., -1., -7.], [6., -1., 5.]);
/// let b = a.submatrix(1, 0);
/// assert_eq!(b.determinant(), 25.0);
/// assert_eq!(b.determinant(), a.minor(1, 0));
/// ```
pub fn minor(&self, row: usize, col: usize) -> f32 {
self.submatrix(row, col).determinant()
}
}
impl Index<(usize, usize)> for Matrix3x3 {
type Output = f32;