% Lecture 9, Experiment 2 % generating plot showing singular values of a matrix % affected by roundoff error. clear; close all; % Experiment 2 randn('state',sum(100*clock)); % initialize random number generator [U,X] = qr(randn(80)); [V,X] = qr(randn(80)); S = diag(2.^(-1:-1:-80)); A = U*S*V; [QC,RC] = clgs(A); [QM,RM] = mgs(A); rc = diag(RC); rm = diag(RM); N = 80; j = 1:1:N; figure; hold on; plot(j',log10(abs(rc)),'o',... j',log10(abs(rm)),'x',... [1;80],[-8;-8],'r-',... [1;80],[-16;-16],'k-'); xlabel('j'); ylabel('log_{10}(r_{jj})'); legend('Classical Gram-Schmidt','Modified Gram-Schmidt',... 'sqrt(\epsilon_{machine}','\epsilon_{machine}'); grid on; axis([0 80 -25 0]);