diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-29 02:43:28 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-29 02:43:28 +0000 |
commit | 764524f65b1b27a0670c81e3605a9ac8e3385040 (patch) | |
tree | 011a4a07ad14dd9a4a23dea7b5f6c8e525c811b3 /lib | |
parent | dc38c877792287240f7ee37d6444da9801a21f57 (diff) | |
download | ruby-764524f65b1b27a0670c81e3605a9ac8e3385040.tar.gz |
* lib/matrix.rb: Add Matrix#adjucate
patch by gogo tanaka [#10056]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/matrix.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb index cdaa55f157..f7acd9f1fc 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -62,6 +62,7 @@ end # * #minor(*param) # * #first_minor(row, column) # * #cofactor(row, column) +# * #adjugate # * #laplace_expansion(row_or_column: num) # * #cofactor_expansion(row_or_column: num) # @@ -690,6 +691,20 @@ class Matrix end # + # Returns the adjugate of the matrix. + # + # Matrix[ [7,6],[3,9] ].adjugate + # => 9 -6 + # -3 7 + # + def adjugate + Matrix.Raise ErrDimensionMismatch unless square? + Matrix.build(row_count, column_count) do |row, column| + cofactor(column, row) + end + end + + # # Returns the Laplace expansion along given row or column. # # Matrix[[7,6], [3,9]].laplace_expansion(column: 1) |