Problem with QR method for Hessenberg matrices
9 views (last 30 days)
Show older comments
In trying to implement the method, my approach is to use a reduction to Hessenberg form, and then to iterate using a QR method of Givens rotations. However, I am having trouble successfully implementing the Givens rotations, since I'm only worried about the n−1 entries of the off-diagonal, in a manner of speaking. Included is my MATLAB code:
function [H,Q,R] = hessQR(A,maxIter)
[H,P] = HHhess(A);
for k = 1:maxIter
[Q,R] = HGivQR(H);
A = R*Q;
end
end
function [Q,R] = HGivQR(A)
n = size(A,1);
Q=eye(n);
R=A;
for j=1:n-1
for i=n:(-1):j+1
x=R(:,j);
if norm([x(i-1),x(i)])>0
c=x(i-1)/norm([x(i-1),x(i)]);
s=-x(i)/norm([x(i-1),x(i)]);
G=eye(n);
G([i-1,i],[i-1,i])=[c,s;-s,c];
R=G'*R;
Q=Q*G;
end
end
end
end
The method converges, but my real Schur decomposition (which is R in my code) is not correct... nor is A==Q*R. I'm not sure what I'm doing wrong, but I think it might be in my Givens code. Please, point out mistakes you see that I have made!
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!