aboutsummaryrefslogtreecommitdiffstats
path: root/lib/matrix.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb15
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)