function histogram_pdf ( x, bin_num )

%*****************************************************************************80
%
%% histogram_pdf() makes a PDF-normalized histogram of data.
%
%  Discussion:
%
%    The MATLAB function histogram() includes an option to estimate the
%    PDF of a set of data using a histogram.  This requires normalizing
%    the data.  The Octave function hist() claims to have a similar option,
%    but there is no useful documentation for the normalization parameter,
%    and various experiments have failed to determine the proper usage.
%
%    This function works out a normalization and then calls the Octave bar()
%    function to get a plot that is roughly equivalent to the MATLAB plot.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 December 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real x(:): the data.
%
%    integer bin_num: the number of bins to use.
%

%
%  The Octave function hist(), normally used to make a histogram of data,
%  can instead return the population and centers of the bins generated 
%  by the data.
%
  [ bin_pop, bin_center ] = hist ( x, bin_num );
%
%  Compute the bin width.
%
  dx = bin_center(2) - bin_center(1);
%
%  Determine a scale so that the data "integrates" to 1.
%
  scale = sum ( bin_pop ) * dx;
  y = bin_pop / scale;
%
%  Call the Octave function bar().
%
  bar ( bin_center, y );

  return
end

