public static double Determinant(MatrixC m) { double result = 0.0; if (!m.IsSquared()) { throw new ArgumentOutOfRangeException( "Dimension", m.GetRows(), "The matrix must be squared!"); } if (m.GetRows() == 1) result = m[0, 0]; else { for (int i = 0; i < m.GetRows(); i++) { result += Math.Pow(-1, i)*m[0, i] * Determinant(MatrixC.Minor(m, 0, i)); } } return result; }
public static MatrixC Adjoint(MatrixC m) { if (!m.IsSquared()) { throw new ArgumentOutOfRangeException( "Dimension", m.GetRows(), "The matrix must be squared!"); } MatrixC ma = new MatrixC(m.GetRows(), m.GetCols()); for (int i = 0; i < m.GetRows(); i++) { for (int j = 0; j < m.GetCols(); j++) { ma[i, j] = Math.Pow(-1, i + j) * (Determinant(Minor(m, i, j))); } } return ma.GetTranspose(); }