function flies_pdf_plot ( n )

%*****************************************************************************80
%
%% flies_pdf_plot() plots the estimated PDF for the flies simulation.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    22 July 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer n: the number of times the experiment is carried out.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'flies_pdf_plot()\n' );
  fprintf ( 1, '  Two flies land at random on a plate of radius 1.\n' );
  fprintf ( 1, '  D is the distance between them.\n' );
  fprintf ( 1, '  Estimate the PDF for D with a plot.\n' );

  d = flies_simulation ( n );
%
%  Plot a histogram.
%
  clf ( );
  hold ( 'on' );
  histogram ( d, 'normalization', 'pdf' );
  grid ( 'on' );
  title ( 'PDF for the two fly simulation' );
  xlabel ( '<-- Distance from center -->' );
  ylabel ( '<-- Probability -->' );
  d2 = linspace ( 0.0, 2.0, 101 );
  pdf = d2 .* ( 4.0 * acos ( d2 / 2 ) - d2 .* sqrt ( 4.0 - d2.^2 ) ) / pi;
  plot ( d2, pdf, 'linewidth', 3 );
  hold ( 'off' )

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

  return
end

