% PEng 7.3
%Jeannette Spuhler for the exercise 2012/10/26
clear all

for i = [100 1000 5000]
   A = sprandn(i, i, 5/i);
   
   for j=1:i
       A(j,j)=1;
   end
  
   b = sprandn(i, 1, i);
  
   % a)
  
   A_full = full(A);
  
   % b)
   if i == 100
       spy(A)
   end
  
   % c)
   b_full = full(b);
   whos
  
   % d)
   tstart = tic;
   x = A \ b;   
   t = toc(tstart);
  
   tstart2 = tic;
   x = A_full \ b_full;
   t2 = toc(tstart2);

   disp(['Solving took ' num2str(t) ' sparse ' num2str(t2) ' full (' num2str(i) 'x' num2str(i) ')'] )
  
   clear t t2 tstart tstart2 x
end



