function pierror ( trial_num )

%*****************************************************************************80
%
%% pierror() estimates pi by counting random points in a square.
%
%  Discussion:
%
%    The square has area 1, the quarter circle area pi/4.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  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.
%    
%  Input:
%
%    integer trial_num: the number of trials.
%
  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' );
  fprintf ( 1, '\n' );

  p = 0;
  for k = 1 : trial_num
    x = rand ( );
    y = rand ( );
    if ( x^2 + y^2 < 1.0 )
      p = p + 1;
    end
  end

  pi_estimate = p / trial_num;
  abs_err = abs ( pi - pi_estimate );
 
  fprintf ( 1, '  Using %d points, estimate is %g, absolute error %g\n', ...
    trial_num, pi_estimate, abs_err );

  return
end
