Module: Matrix::LU

Defined in:
lib/extendmatrix.rb

Class Method Summary collapse

Class Method Details

.factorization(mat) ⇒ Object

LU factorization: A = LU where L is lower triangular and U is upper triangular



720
721
722
723
724
725
726
727
728
729
730
731
# File 'lib/extendmatrix.rb', line 720

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



710
711
712
713
714
715
# File 'lib/extendmatrix.rb', line 710

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



699
700
701
702
703
704
705
706
# File 'lib/extendmatrix.rb', line 699

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