Search code examples
matlabmathmatrixqr-decomposition

Computing the Hessenberg matrix using Givens-rotations


I am making an implementation in matlab to compute the Hessenberg matrix of a given matrix A. I understand the math and i calculated it manualy but i keep comming to the same solution.

Matrix A =

-149.0000  -42.2037 -156.3165
 537.6783  152.5511  554.9272
        0   -0.0728    2.4489

My result =

-149.0000  -42.2037 -156.3165
 537.6783  152.5511  554.9272
        0   -0.0728    2.4489

Result of hess in matlab =

-149.0000   42.2037 -156.3165
-537.6783  152.5511 -554.9272
        0    0.0728    2.4489

The result i obtained is from using only one Given rotation

G{1}(3,4)

1.0000         0         0
     0    0.9987    0.0502
     0   -0.0502    0.9987

G{1}(3,4).transpose * A * G{1}(3,4) should get met the right solution.

As you can see the result i obtain has some minus signs where they don't belong. Is my implementation wrong or is the hess implementation wrong or are they both valid?

Many thanks in advance!


Solution

  • Both are valid. Note that:

    • The Hessenberg decomposition of a matrix is not unique. For instance, diagonal matrices with +/-1 down the diagonal are orthogonal; if you just pick one of these and conjugate your Hessenberg decomposition by it, you get a different Hessenberg decomposition.
    • Your A is already in upper Hessenberg form. Nothing needs to be done to get it into upper Hessenberg form; you can take P = I and H = A.

    I would hazard a guess that Matlab uses Householder transformations rather than Givens rotations to reduce matrices to upper Hessenberg form. Householder transformations are reflections and thus have negative determinant. This can flip some off-diagonal signs.