aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-09 20:35:28 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-09 20:35:28 +0000
commit655cb34f17c2dc4b84aaf3fa99cceabb830138b8 (patch)
treeb004e74904c0e02274761fd533d472d6a4898861
parentb4da2534005f65087ddd0607963fdb4dbc71ce61 (diff)
downloadruby-655cb34f17c2dc4b84aaf3fa99cceabb830138b8.tar.gz
* lib/matrix.rb (Matrix#inverse_from): use #quo. backported r9490.
* lib/matrix.rb (Matrix#determinant): ditto. [ruby-core:27507] * lib/matrix.rb (Matrix#rank): ditto. * lib/matrix.rb (Matrix::Scalar#initialize): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--lib/matrix.rb2
-rw-r--r--test/matrix/test_matrix.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index e0095e929e..222bf4b698 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -569,7 +569,7 @@ class Matrix
#
# Returns the inverse of the matrix.
- # Matrix[[1, 2], [2, 1]].inverse
+ # Matrix[[-1, -1], [0, -1]].inverse
# => -1 1
# 0 -1
#
diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb
index 8e0848de01..6b9b587c6d 100644
--- a/test/matrix/test_matrix.rb
+++ b/test/matrix/test_matrix.rb
@@ -144,4 +144,13 @@ class TestMatrix < Test::Unit::TestCase
assert_equal 3, m.transpose.rank
end
end
+
+ def test_inverse
+ assert_equal(Matrix[[-1, 1], [0, -1]], Matrix[[-1, -1], [0, -1]].inverse)
+ end
+
+ def test_determinant
+ assert_equal(45, Matrix[[7,6], [3,9]].determinant)
+ assert_equal(-18, Matrix[[2,0,1],[0,-2,2],[1,2,3]].determinant)
+ end
end