From c8e23882574a7cf14c5800369ca1e838eea7fe88 Mon Sep 17 00:00:00 2001 From: marcandre Date: Fri, 1 Jul 2011 06:23:12 +0000 Subject: * lib/matrix: Add LUP decomposition git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/matrix.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/matrix.rb') diff --git a/lib/matrix.rb b/lib/matrix.rb index 5ce130221f..b4ff31a218 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -98,6 +98,8 @@ end # Matrix decompositions: # * #eigen # * #eigensystem +# * #lup +# * #lup_decomposition # # Complex arithmetic: # * conj @@ -122,6 +124,7 @@ class Matrix include Enumerable include ExceptionForMatrix autoload :EigenvalueDecomposition, "matrix/eigenvalue_decomposition" + autoload :LUPDecomposition, "matrix/lup_decomposition" # instance creations private_class_method :new @@ -1187,6 +1190,21 @@ class Matrix end alias eigen eigensystem + # + # Returns the LUP decomposition of the matrix; see +LUPDecomposition+. + # a = Matrix[[1, 2], [3, 4]] + # l, u, p = a.lup + # l.lower_triangular? # => true + # u.upper_triangular? # => true + # p.permutation? # => true + # l * u == a * p # => true + # a.lup.solve([2, 5]) # => Vector[(1/1), (1/2)] + # + def lup + LUPDecomposition.new(self) + end + alias lup_decomposition lup + #-- # COMPLEX ARITHMETIC -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #++ -- cgit v1.2.3