From 004c34f9de58067e627eb714083ca99b17e3fcfd Mon Sep 17 00:00:00 2001 From: marcandre Date: Fri, 1 Jul 2011 06:13:35 +0000 Subject: * lib/matrix: Add Eigenvalue Decomposition git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/matrix.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/matrix.rb') diff --git a/lib/matrix.rb b/lib/matrix.rb index 12f99925bc..8c6b3d6e87 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -95,6 +95,10 @@ end # * #transpose # * #t # +# Matrix decompositions: +# * #eigen +# * #eigensystem +# # Complex arithmetic: # * conj # * conjugate @@ -117,6 +121,7 @@ end class Matrix include Enumerable include ExceptionForMatrix + autoload :EigenvalueDecomposition, "matrix/eigenvalue_decomposition" # instance creations private_class_method :new @@ -1162,6 +1167,23 @@ class Matrix end alias t transpose + #-- + # DECOMPOSITIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + #++ + + # + # Returns the Eigensystem of the matrix; see +EigenvalueDecomposition+. + # m = Matrix[[1, 2], [3, 4]] + # v, d, v_inv = m.eigensystem + # d.diagonal? # => true + # v.inv == v_inv # => true + # (v * d * v_inv).round(5) == m # => true + # + def eigensystem + EigenvalueDecomposition.new(self) + end + alias eigen eigensystem + #-- # COMPLEX ARITHMETIC -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #++ -- cgit v1.2.3