function dot_vector_graphs ( log_max )

%*****************************************************************************80
%
%% DOT_VECTOR_GRAPHS generates and plots timings for the dot product operation.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    17 December 2011
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer LOG_MAX, the log base 2 of the maximum value of N
%    to try.  A value of 25 is roughly as big as you can go without
%    hitting memory restrictions.
%
  if ( nargin < 1 )
    log_max = 24;
  end

  speed_limit = 2800000000;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'DOT_VECTOR_GRAPHS\n' );
  fprintf ( 1, '  Compute the dot product of two N-vectors,\n' );
  fprintf ( 1, '  using MATLAB''s vectorized operation.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Do this for vectors of size 2^0, 2^1, ..., 2^%d\n', log_max );
  fprintf ( 1, '  Do this 5 times, to display the variation in timing.\n' );
%
%  Do Time Plots.
%
  clf
  hold on

  for trial = 1 : 5

    n = 1;
    k = 0;

    for logn = 0 : log_max
 
      x = rand ( n, 1 );
      y = rand ( n, 1 );

      tic;
      z = x' * y;
      t = toc;

      k = k + 1;
      xplot(k) = 4*n+2;
      yplot(k) = t;
      n = n * 2;

    end

    plot ( r8_log_2 ( xplot ), r8_log_2 ( yplot ), '-*', 'LineWidth', 2, 'MarkerSize', 10 );

  end

  grid on
  xlabel ( 'Log2(Number of vector entries)' );
  ylabel ( 'Log2(TicToc Time in Seconds)' );
  title ( '5 TRIALS: Dot product time versus vector size' );
  axis equal
  print -dpng 'dot_vector_time_graphs.png'

  hold off
%
%  Do Rate Plots.
%
  clf
  hold on

  for trial = 1 : 5

    n = 1;
    k = 0;

    for logn = 0 : log_max
 
      x = rand ( n, 1 );
      y = rand ( n, 1 );

      tic;
      z = x' * y;
      t = toc;

      k = k + 1;
      xplot(k) = 4*n+2;
      yplot(k) = t;
      n = n * 2;

    end

    plot ( r8_log_2 ( xplot ), r8_log_2 ( xplot ./ yplot ), '-*', 'LineWidth', 2, 'MarkerSize', 10 );

  end

  zplot(1:log_max+1) = r8_log_2 ( speed_limit );
  plot ( r8_log_2 ( xplot ), zplot, 'r-', 'LineWidth', 2 );

  grid on
  xlabel ( 'Log2(Number of vector entries)' );
  ylabel ( 'Log2(Computational Rate)' );
  title ( '5 TRIALS: Dot product rate versus vector size' );
  axis equal
  print -dpng 'dot_vector_rate_graphs.png'

  hold off

  return
end
function value = r8_log_2 ( x )

%*****************************************************************************80
%
%% R8_LOG_2 returns the logarithm base 2 of |X|.
%
%  Discussion:
%
%    R8_LOG_2 ( X ) = Log ( |X| ) / Log ( 2.0 )
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license. 
%
%  Modified:
%
%    21 March 2004
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real X, the number whose base 2 logarithm is desired.
%    X should not be 0.
%
%    Output, real VALUE, the logarithm base 2 of the absolute
%    value of X.  It should be true that |X| = 2**R8_LOG_2.
%
  if ( x == 0.0 )
    value = -inf;
  else
    value = log ( abs ( x ) ) / log ( 2.0 );
  end

  return
end

