module Matrix::Hessenberg
Public Class Methods
QR(mat)
click to toggle source
the matrix must be an upper R^(n x n) Hessenberg
matrix
# 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