From 264dd7cfec1d91a2f3a6045ce2155b1e7b89e93f Mon Sep 17 00:00:00 2001 From: gogotanaka Date: Sat, 11 Oct 2014 23:43:44 -0700 Subject: [PATCH 2/3] Implement Matrix#adjugate --- lib/matrix.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/matrix.rb b/lib/matrix.rb index b39973b..960bb6c 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) -- 1.9.3 (Apple Git-50)