function chebyshev13_test ( )

%*****************************************************************************80
%
%% chebyshev13_test() does histogram sampling on the Chebyshev13 PDF.
%
%  Discussion:
%
%    This PDF is infinite at the endpoints.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 March 2026
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'chebyshev13_test():\n' );
  fprintf ( 1, '  From the Chebyshev13 PDF formula, create a\n' );
  fprintf ( 1, '  histogram that can be used for approximation.\n' );
%
%  We want our breakpoints to be at the Chebyshev nodes.
%
  b_n = 17;
  t = ( linspace ( pi, 0.0, b_n + 1 ) )';
  b = cos ( t );
%
%  Create a histogram of the PDF.
%
  [ b_p, b_l, b_m, b_r ] = pdf_to_histogram ( @chebyshev13_pdf, b_n, b );
%
%  Plot the histogrammed PDF and compare with the formula.
%
  figure ( );
  hold ( 'on' );
  [ xp, yp ] = pwc2_plot ( b, b_p );
  plot ( xp, yp, 'b-o', 'Linewidth', 3 );
  grid ( 'on' );
  t = ( linspace ( pi, 0.0, 33 ) )';
  t = t(2:32);
  x = cos ( t );
  y = chebyshev13_pdf ( x );
  plot ( x, y, 'r-', 'Linewidth', 3 );
  title ( 'Chebyshev13 histogrammed PDF' );
  hold ( 'off' );
  filename = 'chebyshev13_pdf.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  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 );
%
%  Plot the histogrammed CDF.
%
  figure ( );
  plot ( c_x, c_y, 'b-o', 'LineWidth', 3 );
  grid ( 'on' );
  title ( 'Chebyshev13 histogrammed CDF' );
  filename = 'chebyshev13_cdf.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Sample the discrete CDF.
%
  s_n = 100000;
  s = cdf_to_sample ( c_x, c_y, c_n, s_n );
%
%  Plot the samples.
%
  figure ( );
  hold ( 'on' );

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

  t = ( linspace ( pi, 0.0, 33 ) )';
  t = t(2:32);
  x = cos ( t );
  y = chebyshev13_pdf ( x );
  plot ( x, y, 'r-', 'Linewidth', 3 );
  title ( 'Chebyshev13 histogrammed CDF samples' );
  hold ( 'off' );
  filename = 'chebyshev13_histogram.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end
