From f5d79908f68679ffb654054a91c5d62b54edf66d Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Thu, 1 Jul 2021 21:29:58 -0700 Subject: [PATCH] implement minor for matrix3x3 --- rtchallenge/src/matrices.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rtchallenge/src/matrices.rs b/rtchallenge/src/matrices.rs index de29a4e..475ae54 100644 --- a/rtchallenge/src/matrices.rs +++ b/rtchallenge/src/matrices.rs @@ -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;