summaryrefslogtreecommitdiff
path: root/lib/matrix.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-01 06:23:12 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-01 06:23:12 +0000
commitc8e23882574a7cf14c5800369ca1e838eea7fe88 (patch)
tree172940bc91505bfa398089c7f2b446e4650a51e6 /lib/matrix.rb
parent59a3d59496607ebeb618fd781d3af9a6bc8c647e (diff)
* lib/matrix: Add LUP decomposition
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 5ce1302..b4ff31a 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -98,6 +98,8 @@ end
# Matrix decompositions:
# * <tt> #eigen </tt>
# * <tt> #eigensystem </tt>
+# * <tt> #lup </tt>
+# * <tt> #lup_decomposition </tt>
#
# Complex arithmetic:
# * <tt> conj </tt>
@@ -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 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#++