public SquareMatrix Inverse() { var matrix = Augment(Identity(Size)); matrix.MakeRowEchelon(); var squareMatrix = new SquareMatrix(Size); var squareMatrix2 = new SquareMatrix(Size); for (var i = 0; i < Size; i++) { squareMatrix.SetColumn(i, matrix.GetColumn(i)); squareMatrix2.SetColumn(i, matrix.GetColumn(i + Size)); } for (var j = 0; j < squareMatrix.Rows; j++) { if (squareMatrix.IsRowZero(j)) { throw new MatrixException("Matrix is singular"); } } for (var k = Size - 1; k > 0; k--) { for (var l = k - 1; l >= 0; l--) { var scalar = -squareMatrix[l, k]; squareMatrix.AddRowTimesScalar(l, k, scalar); squareMatrix2.AddRowTimesScalar(l, k, scalar); } } return squareMatrix2; }
public double Determinant() { var squareMatrix = new SquareMatrix(this); var num = squareMatrix.MakeRowEchelon(); double result; for (var i = 0; i < Size; i++) { if (squareMatrix.IsRowZero(i)) { result = 0.0; return result; } } result = num; return result; }