My Hessenberg Decomposition code is not working

3 visualizaciones (últimos 30 días)
Jeremy Dessert
Jeremy Dessert el 2 de Mzo. de 2021
Respondida: Christine Tobler el 2 de Mzo. de 2021
I am writing a function to find the Hessenberg decomposition of a matrix. I tried to check my code with the following matrix: [2 1 1; 1 2 1; 1 1 2]. When I did
househess(A) the output was [ 2 -1.41 0; -1.41 3 0; 0 0 1]. This is different from the built in function hess on matlab. I cannot see what I am doing
wrong in my code that I attached below:
function H = househess(A) % returns househess form
n = size(A); % square matrix
H = A;
for k= 1:n-2
x = H(k+1:n,k);
x(1)= sign(x(1))*norm(x) + x(1);
v = x/norm(x);
H(k+1:n,:) = H(k+1:n,:) - 2*v*(v'*H(k+1:n,:));
H(:,k+1:n) = H(:,k+1:n)-(H(:,k+1:n)*(2*v))*v';
end

Respuestas (1)

Christine Tobler
Christine Tobler el 2 de Mzo. de 2021
Your code looks correct, try it with A = randn(10) for example - this matches the outputs of HESS quite closely. When the input to HESS is symmetric, a specific algorithm for that case is used which returns an exactly symmetric and tridiagonal matrix (try with A = randn(10); A = A + A').
That algorithm seems to be using some different scalings in the Householder transformations, but the final result has the same properties as in the nonsymmetric case otherwise (that is, eig(hess(A)) matches eig(A)).

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by