function square_distance_test ( )

%*****************************************************************************80
%
%% square_distance_test() tests square_distance().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 April 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../square_distance' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'square_distance_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test square_distance().\n' );
%
%  Because of the way we compute the PDF, we sometimes compute 
%  (and ignore) square roots of negative numbers.
%  We need to tell MATLAB not to worry!
%
  warning ( 'off', 'MATLAB:plot:IgnoreImaginaryXYPart' )

  n = 10000;
  [ mu, var ] = square_distance_stats ( n );
  mu_exact = ( sqrt ( 2.0 ) + 2.0 + 5.0 * log ( 1.0 + sqrt ( 2.0 ) ) ) / 15.0;
  var_exact = ( 69.0 - 4.0 * sqrt ( 2.0 ) ...
    - 10.0 * ( 2.0 + sqrt ( 2.0 ) ) * asinh ( 1.0 ) ...
    - 25.0 * ( asinh ( 1.0 ) )^2 ) / 225.0;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Using N = %d sample points,\n', n );
  fprintf ( 1, '  Estimated mean distance = %g\n', mu );
  fprintf ( 1, '  Exact mean distance     = %g\n', mu_exact );
  fprintf ( 1, '  Estimated variance      = %g\n', var );
  fprintf ( 1, '  Exact variance          = %g\n', var_exact );

  n = 10000;
  square_distance_histogram ( n );
  filename = 'square_distance_histogram.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );

  square_distance_pdf ( );
  filename = 'square_distance_pdf.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );

  clf ( );
  hold ( 'on' );
  n = 10000;
  square_distance_histogram ( n );
  square_distance_pdf ( );
  hold ( 'off' );
  filename = 'square_distance_compare.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'square_distance_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../square_distance' );

  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

