function pierror ( )

%*****************************************************************************80
%
%% PIERROR estimates pi by counting random points in a square.
%
%  Discussion:
%
%    The square has area 1, the quarter circle area pi/4.
%
%  Modified:
%
%    22 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%    
  fprintf ( 1, '\n' );
  fprintf ( 1, 'PIERROR:\n' );
  fprintf ( 1, '  Estimate pi by counting random points in the unit\n' );
  fprintf ( 1, '  square which are also in the quarter circle.\n' );

  number_of_points(1) = 100;
  number_of_points(2) = 10000;

  fprintf ( 1, '\n' );

  for j = 1 : 2
    N = number_of_points(j);
    for loop = 1 : 1000
      P = 0;
      for k = 1 : N
        x = rand ( );
        y = rand ( );
        if ( x^2 + y^2 < 1.0 )
          P = P + 1;
        end
      end
      error(loop) = ( 4.0 * P - pi * N ) * 100 / ( N * pi );
    end

    fprintf ( 1, '  Using %d points, estimate is %g, percentage error %g\n', ...
      N, 4.0 * P / N, error(loop) );

  end

  return
end