% % This is JEM modification to plot errors also. % % % Matlab code qrplt.m % For "Applied Numerical Linear Algebra", Question 4.15 % Written by James Demmel, Oct 25, 1995 % Modified, Jun 5, 1997 % % 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 clg plot(e','k'),grid title('plot of each diagonal matrix entry during QR iteration') % % MODIFIED STUFF FROM HERE % % Column i+1 of the matrix e contains the ith estimate for the % eigenvalues, generated in the ith step through the loop. % % The best estimate for the eigenvalues generated by the algorithm % should be contained in the last column of e, so we set evals to % be this estimate. % We put the estimates in a n by (m+1) matrix evalsm with each % column of evalsm being a copy of this best estimate for the eigenvalues. % evals=e(1:n,m+1) evalsm=evals; for i=1:m evalsm=[evalsm,evals]; end evalsm; % % The error is the absolute value of the difference between % the iterates (stored in e) and the best estimate of the eigenvalues % (stored in evalsm) % % The (m+1)st column of error will be a column of zeroes, so we rescale % error to ignore it. % error=abs(e-evalsm); error=error(1:n,1:m); % % Calculate the log of this error and plot it out. % logerror=log(error); plot(logerror','k'),grid title('plot of log error of each diagonal matrix entry during QR iteration')