function chebyshev2_test ( )

%*****************************************************************************80
%
%% chebyshev2_test() does histogram sampling on the Chebyshev2 PDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 March 2026
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'chebyshev2_test():\n' );
  fprintf ( 1, '  From the Chebyshev2 PDF formula, create a\n' );
  fprintf ( 1, '  histogram that can be used for approximation.\n' );
%
%  Create the histogram from the PDF.
%
  b_n = 21;
  b = ( linspace ( -1.0, 1.0, b_n + 1 ) )';
  [ b_p, b_l, b_m, b_r ] = pdf_to_histogram ( @chebyshev2_pdf, b_n, b );

  figure ( );
  hold ( 'on' );
  bar ( b_m, b_p );
  x = ( linspace ( -1.0, +1.0, 51 ) )';
  y = chebyshev2_pdf ( x );
  plot ( x, y, 'r-', 'Linewidth', 3 );
  hold ( 'off' );
  filename = 'chebyshev2_pdf.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Create the CDF from the PDF.
%
  [ c_x, c_y, c_n ] = histogram_to_cdf ( b_p, b_l, b_r, b_n );

  figure ( );
  hold ( 'on' );
  bar ( c_x, c_y );
  x = ( linspace ( -1.0, +1.0, 51 ) )';
  y = chebyshev2_cdf ( x );
  plot ( x, y, 'r-', 'Linewidth', 3 );
  filename = 'chebyshev2_cdf.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Sample the discrete CDF.
%
  s_n = 10000;
  s = cdf_to_sample ( c_x, c_y, c_n, s_n );

  figure ( );
  hold ( 'on' );

  bin_num = 21;
  histogram_pdf ( s, bin_num );
% histogram ( s, c_x, 'Normalization', 'pdf' );

  x = ( linspace ( -1.0, +1.0, 51 ) )';
  y = chebyshev2_pdf ( x );
  plot ( x, y, 'r-', 'Linewidth', 3 );
  hold ( 'off' );
  filename = 'chebyshev2_histogram.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end
