clear
%
%  Calculate the usual way, and plot in blue.
%
m = 1000;
a = zeros ( m, m );
n = 1;
k = 0;
for logn = 0 : 10
  tic;
  for i = 1 : m
    for j = 1 : n
      a(i,j) = sin ( i * pi / m ) * exp ( j * pi / n );
    end
  end
  t = toc;
  k = k + 1;
  x1(k) = m * n;
  y1(k) = t;
  n = n * 2;
end
plot ( x1, y1, 'b-*', 'LineWidth', 2, 'MarkerSize', 10 );
%
%  Repeat the calculation.  Plot in red this time.
%
hold on

m = 1000;
n = 1;
k = 0;
for logn = 0 : 10
  tic;
  s = sin ( ( 1 : m ) * pi / m );
  e = exp ( ( 1 : n ) * pi / n );
  a = s' * e;
  t = toc;
  k = k + 1;
  x2(k) = m * n;
  y2(k) = t;
  n = n * 2;
end
plot ( x2, y2, 'r-*', 'LineWidth', 2, 'MarkerSize', 10 );


grid on
xlabel ( 'Number of matrix entries' );
ylabel ( 'TicToc Time in Seconds' );
title ( 'Time versus matrix size' );
hold off

fprintf ( 1, '\n' );
fprintf ( 1, '       M       N     Time1     Time2     Rate1     Rate2\n' );
fprintf ( 1, '\n' );

m = 1000;
n = 1;
k = 0;
for logn = 0 : 10
  k = k + 1;
  r1 = x1(k) / y1(k);
  r2 = x2(k) / y2(k);
  fprintf ( 1, '  %6d  %6d  %8.2g  %8.2g  %8.2g  %8.2g\n', m, n, y1(k), y2(k), r1, r2 );
  n = n * 2;
end
