% Matlab code qrplt.m
% For "Applied Numerical Linear Algebra",  Question 4.15
% Written by James Demmel, Oct 25, 1995
% Modified by Ivar Gustafsson, 2003
%  Plot the diagonal entries of a matrix undergoing unshifted QR iteration
%
%  Inputs:
%    a = matrix
%    m = number of QR iterations
%
%  Outputs:
%    n curves, one for each diagonal entry of a 
%
hold off
e=diag(a);
for i=1:m,
   [q,r]=qr(a);dd=diag(sign(diag(r)));r=dd*r;q=q*dd;a=r*q; ...
   e=[e,diag(a)];
end
clf
plot(e','k'),grid        %first question here
title('plot of each diagonal matrix entry during QR iteration')
%e=e-e(:,length(e))*ones(1,length(e));  %new question here
%err=[];   
%for i=1:length(e), err=[err norm(e(:,i))];end
%plot(log(err(1:length(err)-1)))
%title(' plot of log of error versus iteration number')
