method
cofactor
ruby latest stable - Class:
Matrix
cofactor(row, column)public
Returns the (row, column) cofactor which is obtained by multiplying the first minor by (-1)**(row + column).
Matrix .diagonal (9, 5, -3, 4).cofactor (1, 1) => -108
# File lib/matrix.rb, line 613
def cofactor(row, column)
raise RuntimeError, "cofactor of empty matrix is not defined" if empty?
Matrix.Raise ErrDimensionMismatch unless square?
det_of_minor = first_minor(row, column).determinant
det_of_minor * (-1) ** (row + column)
end