function [ b_p, b_l, b_m, b_r ] = pdf_to_histogram ( pdf, b_n, b )

%*****************************************************************************80
%
%% pdf_to_histogram() creates a histogram given a PDF.
%
%  Discussion:
%
%    We assume the PDF is defined over the domain [-1,+1].
%
%    This process is extendible to any finite domain.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 August 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real PDF ( N, X ), a function which returns a vector of PDF
%    values at the N points X.
%
%    integer  B_N, the number of bins to create.
%
%    real B(B_N+1), the breakpoints for the bins.
%
%  Output:
%
%    integer B_P(B_N), normalized PDF values associated with the bins.
%
%    integer B_L(B_N), B_M(B_N), B_R(B_N), left, middle, and right
%    points associated with each bin.
%

%
%  Bin I has limits B_L(I) <= X <= B_R(I).
%
  b_l = b(1:b_n,1);
  b_r = b(2:b_n+1,1);
%
%  Bin I has midpoint B_M(I).
%
  if ( b_n == 1 )
    b_m = 0.0;
  else
    b_m = 0.5 * ( b(1:b_n,1) + b(2:b_n+1,1) );
  end
%
%  Assign Bin I the nominal PDF value B_P(I) evaluated at B_M(I).
%
  b_p = pdf ( b_m );

  return
end

