% % alias.m % % %% Code used to generate the figures and ranks for Case ii: n = 101, p = 1000 for Example 10.7. % This can be easily modified for Case i: p = n = 5. % clear all % close all n = 101; p = 1000; % n = 5; % p = 5; h = 1/(n-1); t = 0:h:1; tol = 1e-10; [I,T] = meshgrid(1:p,t); A = sin(2*pi*I.*T); rank(A,tol) % % RandSVD on A (using an oversampling of 10) % k = 65; tic [U1,S1,V1] = randsvd(A,k,10); toc % % RandSVD on A^T (note that the left and right singular vectors change places % tic [V2,S2,U2] = randsvd(A',k,10); toc % % Compute the SVD of A for comparison to the randomized results. % S = svd(A); % % Plot the aliasing results, singular values and comparison of the singular values. % figure(1) % plot(t,A(:,1),'b--',t,A(:,2),'-k',t,A(:,3),'b-.',t,0*t,'k-','linewidth',3) plot(t,A(:,1),'-k',t,A(:,101),'--r',t,A(:,201),'-.b',t,A(:,901),':k','linewidth',3) hold on plot(t,0*t,'k-','linewidth',3) hold off set(gca,'Fontsize',[22]); xlabel('Time (s)') ylabel('Column Entries of A') % legend('A(:,1)','A(:,2)','A(:,3)','Location','South') legend('A(:,1)','A(:,101)','A(:,201)','A(:,901)','Location','NorthEast') figure(2) plot(t,A(:,1),'--b',t,A(:,51),'-r','linewidth',3) hold on plot(t,0*t,'k-','linewidth',3) hold off set(gca,'Fontsize',[22]); xlabel('Time (s)') ylabel('Column Entries of A') legend('A(:,1)','A(:,51)','Location','South') % figure(4) % plot(Q(:,1),'x','linewidth',3) % hold on % plot(V(:,1),'o','linewidth',3) % hold off % set(gca,'Fontsize',[22]); % legend('Q(:,1)','Vs(:,1)','Location','South') % ylabel('First Basis Function for I(q)') figure(3) semilogy(1:k,S(1:k), 'xr', 1:k,diag(S1), 'ob', 'linewidth',3) axis([0 k 1e-13 1e+2]) set(gca,'Fontsize',[22]); legend('Deterministic Algorithm','Randomized Algorithm','Location','East') xlabel('Index') ylabel('Singular Values') Sdiff = abs(S(1:k) - diag(S1)); figure(4) semilogy(Sdiff,'bx','linewidth',4) axis([0 k 1e-14 1e-12]) set(gca,'Fontsize',[22]); xlabel('Index') ylabel('Absolute Difference in Singular Values') % figure, % semilogy(1:k,S(1:k), 'k-', 1:k, diag(S1), 'r:', 1:k, diag(S2), 'b--', 'LineWidth',3); % xlabel('Index') % ylabel('Singular Values') % legend('True', 'RandSVD A', 'RandSVD A^T'); % set(gca, 'FontSize', 18);