function distance_histogram_compare ( n )

%
%  Because of the way we compute the PDF, we sometimes compute 
%  (and ignore) square roots of negative numbers.
%  We need to tell MATLAB not to worry!
%
  warning ( 'off', 'MATLAB:plot:IgnoreImaginaryXYPart' )

  p1 = rand(2,n);
  p2 = rand(2,n);
  d = vecnorm ( p1 - p2 );
  hold ( 'on' );
  bins = 20;
  histogram ( d, bins, 'Normalization', 'pdf' )

  d = linspace ( 0.0, sqrt ( 2.0 ), 101 );

  pdf = 2.0 * d .* ( d.^2 - 4.0 * d + pi ) .* ( d <= 1.0 ) ...
      + 2.0 * d .* (4.0 .* sqrt ( d.^2 - 1.0 ) - ( d.^2 + 2.0 - pi ) ...
      - 4.0 * atan ( sqrt ( d.^2 - 1.0 ) ) ) .* ( 1.0 < d );

  plot ( d, pdf, 'r-', 'linewidth', 3 );

  grid ( 'on' );
  xlabel ( '<-- Distance -->', 'fontsize', 12 ); 
  ylabel ( '<-- Relative frequency -->', 'fontsize', 12 );
  title ( 'Observed and theoretical PDF', 'fontsize', 16 );
  hold ( 'off' );

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

  return
end

