diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-01 06:13:35 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-01 06:13:35 +0000 |
commit | 004c34f9de58067e627eb714083ca99b17e3fcfd (patch) | |
tree | a9ae5d66790766d0966d591795d91f2ccb6b47cf /lib/matrix.rb | |
parent | 376b8251271da10ff3571b9a15c25333bb4492bc (diff) | |
download | ruby-004c34f9de58067e627eb714083ca99b17e3fcfd.tar.gz |
* lib/matrix: Add Eigenvalue Decomposition
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r-- | lib/matrix.rb | 22 |
1 files changed, 22 insertions, 0 deletions
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 # * <tt> #transpose </tt> # * <tt> #t </tt> # +# Matrix decompositions: +# * <tt> #eigen </tt> +# * <tt> #eigensystem </tt> +# # Complex arithmetic: # * <tt> conj </tt> # * <tt> conjugate </tt> @@ -117,6 +121,7 @@ end class Matrix include Enumerable include ExceptionForMatrix + autoload :EigenvalueDecomposition, "matrix/eigenvalue_decomposition" # instance creations private_class_method :new @@ -1163,6 +1168,23 @@ class Matrix 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 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #++ |