Created
August 8, 2008 16:57
-
-
Save qoobaa/4584 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'matrix' | |
class Matrix | |
alias old_minor minor | |
def minor(*param) | |
if param.size == 2 and param[0].kind_of?(Integer) and param[1].kind_of?(Integer) | |
rows = [] | |
@rows.size.times do |i| | |
next if i == param[0] | |
rows << (@rows[i][0, param[1]] or []) + | |
(@rows[i][param[1] + 1, @rows.size - param[1] - 1] or []) | |
end | |
Matrix.rows(rows, false) | |
else | |
old_minor(param) | |
end | |
end | |
def adjugate | |
Matrix.Raise ErrDimensionMismatch unless square? | |
rows = Array.new(@rows.size) { [] } | |
rows.size.times do |row| | |
rows.size.times do |col| | |
rows[row][col] = (((row + col) % 2) == 0 ? 1 : -1) * minor(row, col).det | |
end | |
end | |
Matrix.rows(rows, false).t | |
end | |
alias adj adjugate | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment