Module: Matrix::Hessenberg

Defined in:
lib/extendmatrix.rb

Class Method Summary collapse

Class Method Details

.QR(mat) ⇒ Object

the matrix must be an upper R^(n x n) Hessenberg matrix



949
950
951
952
953
954
955
956
957
958
959
960
# File 'lib/extendmatrix.rb', line 949

def self.QR(mat)
  r = mat.clone
  n = r.row_size
  q = Matrix.I(n)
  for j in (0...n-1)
    c, s = Givens.givens(r[j,j], r[j+1, j])
    cs = Matrix[[c, s], [-s, c]]
    q *= Matrix.diag(Matrix.robust_I(j), cs, Matrix.robust_I(n - j - 2))
    r[j..j+1, j..n-1] = cs.t * r[j..j+1, j..n-1]
  end
  return q, r
end