public static decimal Determinant(NMatrix matrix) { if (matrix.Rows != matrix.Columns) { throw new ArgumentException("Determinant calculation failed - the matrix wasn't square."); } decimal result = 0; if (matrix.Rows == 0) { } else if (matrix.Rows == 1) { result = matrix.Data[0, 0]; } else { NMatrix cfs; try { cfs = NMatrix.Cofactors(matrix); } catch (ArgumentException) { // IS THIS CORRECT?! throw new ArgumentException("Determinant calculation failed - this was likely because its determinant was undifined."); } for (int i = 0; i < matrix.Columns; i++) { result += matrix.Data[0, i] * cfs.Data[0, i]; } } return(result); }
public static NMatrix Adjoint(NMatrix matrix) { return(matrix.Cofactors().T()); }
public IMatrix CofactorsMatrix() { return(NMatrix.Cofactors(this)); }