function chebyshev2_sample_test ( )

%*****************************************************************************80
%
%% chebyshev2_sample_test() tests chebyshev2_sample().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 August 2016
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'chebyshev2_sample_test()\n' );
  fprintf ( 1, '  chebyshev2_sample() uses acceptance/rejection sampling\n' );
  fprintf ( 1, '  on the Chebyshev2 density 2/pi * sqrt(1-x^2)\n' );

  n = 100000;

  [ s, n2 ] = chebyshev2_sample ( n );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of samples N = %d\n', n );
  fprintf ( 1, '  Number of trials N2 = %d\n', n2 );
  fprintf ( 1, '  N2/N =       %g\n', n2 / n );
  fprintf ( 1, '  Area ratio = %g\n', 2.0 / ( pi / 2.0 ) );

% histogram ( s, 41, 'Normalization', 'pdf' );

  bin_num = 41;
  [ bin_pop, bin_center ] = hist ( s, bin_num );
  dx = bin_center(2) - bin_center(1);
  scale = sum ( bin_pop ) * dx;
  y = bin_pop / scale;
  bar ( bin_center, y );

  hold ( 'on' );
  x = linspace ( -1.0, +1.0, 42 );
  y = 2.0 / pi * sqrt ( 1.0 - x.^2 );
  plot ( x, y, 'r-', 'Linewidth', 3 );
  axis ( 'equal' );
  hold ( 'off' );

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

  return
end
