Module: Matrix::LU
- Defined in:
- lib/extendmatrix.rb
Class Method Summary collapse
-
.factorization(mat) ⇒ Object
LU factorization: A = LU where L is lower triangular and U is upper triangular.
-
.gauss(mat, k) ⇒ Object
Return the Gauss transformation matrix: M_k = I - tau * e_k^T.
-
.gauss_vector(mat, k) ⇒ Object
Return the Gauss vector, MC, Golub, 3.2.1 Gauss Transformation, p94.
Class Method Details
.factorization(mat) ⇒ Object
LU factorization: A = LU where L is lower triangular and U is upper triangular
743 744 745 746 747 748 749 750 751 752 753 754 |
# File 'lib/extendmatrix.rb', line 743 def self.factorization(mat) u = mat.clone n = u.column_size i = Matrix.I(n) l = i.clone (n-1).times {|k| mk = gauss(u, k) u = mk * u # M_{n-1} * ... * M_1 * A = U l += i - mk # L = M_1^{-1} * ... * M_{n-1}^{-1} = I + sum_{k=1}^{n-1} tau * e } return l, u end |
.gauss(mat, k) ⇒ Object
Return the Gauss transformation matrix: M_k = I - tau * e_k^T
732 733 734 735 736 737 |
# File 'lib/extendmatrix.rb', line 732 def self.gauss(mat, k) i = Matrix.I(mat.column_size) tau = gauss_vector(mat, k) e = i.row2matrix(k) i - tau * e end |
.gauss_vector(mat, k) ⇒ Object
Return the Gauss vector, MC, Golub, 3.2.1 Gauss Transformation, p94
720 721 722 723 724 725 726 727 |
# File 'lib/extendmatrix.rb', line 720 def self.gauss_vector(mat, k) t = mat.column2matrix(k) tk = t[k, 0] (0..k).each{|i| t[i, 0] = 0} return t if tk == 0 (k+1...mat.row_size).each{|i| t[i, 0] = t[i, 0].to_f / tk} t end |