My Hessenberg Decomposition code is not working

조회 수: 3 (최근 30일)
Jeremy Dessert
Jeremy Dessert 2021년 3월 2일
답변: Christine Tobler 2021년 3월 2일
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

답변 (1개)

Christine Tobler
Christine Tobler 2021년 3월 2일
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)).

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by