function hypersphere_angle_test ( )

%*****************************************************************************80
%
%% hypersphere_angle_test() tests hypersphere_angle().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    31 January 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../hypersphere_angle' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hypersphere_angle_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test hypersphere_angle().\n' );

  for m = [ 2, 3, 5, 10, 20, 40, 80, 160 ]
    n = 10000;
    [ cost_mu, cost_std, theta_mu, theta_std ] = hypersphere_angle_stats ( m, n );
    fprintf ( 1, '\n' );
    fprintf ( 1, '  Using M = %d spatial dimension\n', m );
    fprintf ( 1, '  Using N = %d sample points,\n', n );
    fprintf ( 1, '  COST = absolute value of cosine between two random points:\n' );
    fprintf ( 1, '    Estimated mean = %g\n', cost_mu );
    fprintf ( 1, '    Estimated std  = %g\n', cost_std );
    fprintf ( 1, '  THETA = arc cosine of absolute value of cosine between two random points:\n' );
    fprintf ( 1, '    Estimated mean = %g (radians) = %g (degrees)\n', theta_mu, theta_mu * 180.0 / pi );
    fprintf ( 1, '    Estimated std  = %g (radians) = %g (degrees)\n', theta_std, theta_std * ( 180.0 / pi ) );
  end

  m_max = 100;
  x = zeros ( m_max, 1 );
  y = zeros ( m_max, 1 );
  n = 10000;

  for m = 1 : m_max
    [ cost_mu, cost_std, theta_mu, theta_std ] = hypersphere_angle_stats ( m, n );
    x(m) = m;
    y(m) = theta_mu * 180.0 / pi;
  end

  plot ( x, y, 'b-', 'Linewidth', 3 );
  xlabel ( '<-- Spatial dimension -->' );
  ylabel ( '<-- Angle in degrees -->' );
  title ( 'Average (positive) angle between random unit vectors' );
  grid ( 'on' );
  filename = 'hypersphere_angle_test.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hypersphere_angle_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../hypersphere_angle' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

