A1 Scripts

 

 

 

P1
% P1  Illustrates FirstCol
clc 
% Generate the (same) random example
randn('seed',0)
n = 10; H = triu(randn(n,n),-1); r = randn(n-1,1);

disp('  p           Transpose of the first column of (H - r(p)I)*...*(H - r(1)I)')
disp('----------------------------------------------------------------------------------------------')
for p=1:n-1
    v = FirstCol(H,r(1:p));
    disp([sprintf('%3d  ',p) sprintf('%7.3f  ',v)])
end
P2
% P2
clc
r = zeros(1,6);
disp('Ratio of Strassen Flops to Conventional Matrix multiplcation flops...')
disp(' ')
disp('  nMin    n = 2^10   n = 2^12   n = 2^14    n = 2^16   n = 2^18    n = 2^20')
disp('--------------------------------------------------------------------------')
for nMinValues = 2.^(1:9);
   i=0;
   for n = [2^10  2^12  2^14  2^16  2^18   2^20]
        i = i+1;
        r(i) = StrassFlops(n,nMinValues)/(2*n^3);
    end
   disp(sprintf('%5d %10.3f %10.3f %10.3f  %10.3f %10.3f  %10.3f',nMinValues,r(1),r(2),r(3),r(4),r(5),r(6)))   
end


P3
% P3 Examines DFT

clc 
% Display small example..
F = DFT(4);
RealPartofF = real(F)
disp(' ')
ImagPartofF = imag(F)
disp(' ')
% Check error in a large example...
n = 100;
F = DFT(n);
F0 = zeros(n,n);
i = sqrt(-1);
for p=1:n
    for q = 1:n
        theta = 2*pi*(p-1)*(q-1)/n;
        F0(p,q) = cos(theta) - i*sin(theta);
    end
end
disp(sprintf('norm(DFT(%1d) - F_%1d) = %10.3e',n,n,norm(F-F0)))
P4
% P4  Benchmarks FastToep
  clc
  randn('seed',0)
  nRepeatSlow = 10; nRepeatFast = 100; % Play withthese to get reliable benchmarks
  disp('Compare FastToep(c,r,x) with T(c,r)*x ...')
  disp(' ')
  disp('   n        speed-up         error')
  disp('------------------------------------------')
  for n = 100:100:1000
     r = randn(n,1); c = randn(n,1); c(1) = r(1); x = randn(n,1);
     % benchmark the conventional approach...

     tic
     for instance =1:nRepeatSlow
        y1 = toeplitz(c,r)*x;
     end
     tslow = toc/nRepeatSlow;
     % benchmark the fast approach...
  
     tic
     for instance = 1:nRepeatFast
        y = FastToep(c,r,x);
     end
     tfast = toc/nRepeatFast;
     speedup = tslow/tfast;
     err = norm(y-y1)/norm(y);
     disp(sprintf('  %4d   %10.3f        %10.3e',n,speedup,err))
 end