My Hessenberg Decomposition code is not working
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Christine Tobler
am 2 Mär. 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)).
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!