  function ShowSVDS()
% Illustrates svds for certain sparse svd problems
 clc
% Generate an example...
 m = 1000;
 n = 500;
 density = .02;
 A = sprandn(m,n,density);
 fprintf('Approximate the 3 largest singular values:\n\n')
 fprintf('Via svd :')
 sv0 = svd(full(A));
 fprintf('%20.15f',sv0(1:3))
 fprintf('\nVia svds:')
 sv = svds(A,3);
 fprintf('%20.15f',sv(1:3))
 
% Generate a low-rank example...

 fprintf('\n\nA rank-3 example...\n\n')
 m = 2000;
 n = 500;
 density = .02;
 s = .0001*rand(n,1);
 s(1:3) = [1;.7;.5];
 A = sprandn(m,n,density,s);
 [U,S,V] = svds(A,4);
 format short
 fprintf('A = USV'' close to rank 3. Here is S(1:3,1:3)... \n\n')
 disp(S(1:3,1:3))
 fprintf('||A - U(:,1:3)*S(1:3,1:3)*V(:,1:3)'' || = %10.6f\n',...
                  norm(A - U*S*V',1))
 


 
 
 
  
 
 