% QR_eigF.m
% A function using QR iteration to find the
% eigenvalues (& eigenvectors with a little more work)
% of matrix A
% Algorithm 4.7 on p.182 of Heath
% K. Ming Leung, 09/18/03

function eval = QR_eig(A,itMax)
for it = 1:itMax
[Q, R] = QR_factor(A);
A = R*Q,
end
eval = diag(A);

% Function QR_factor computes QR factors of A
function [Q, R] = QR_factor(A)
[n, nn] = size(A); R = A; Q = eye(n);
for k = 1:n-1
x = zeros(n,1);
x(k:n,1) = R(k:n,k);
g = norm(x);
v = x;
v(k) = v(k)+g;
s = norm(v);
w=v/s;
u = 2*R'*w;
R = R-w*u';
Q = Q-2*Q*w*w';
end