function area2 ( n )

%% AREA2 estimates area between X axis and Y=3/4*(1-X^2).

%
%  Define the rectangle that contains the graph.
%
  x_min = -1.5;
  x_max = +1.5;

  y_min = - 15.0 / 16.0;
  y_max = 0.75;
%
%  Define points along the curve so we can plot it.
%
  xp = linspace ( x_min, x_max, 501 );
  yp = f ( xp );
%
%  Choose random X and Y values.
%
  xs = x_min + rand ( n, 1 ) * ( x_max - x_min );
  ys = y_min + rand ( n, 1 ) * ( y_max - y_min );

  yx = f ( xs );

  i = find ( 0.0 <= ys & ys <= yx );
  pos = length ( i );

  j = find ( yx <= ys & ys <= 0.0 );
  neg = length ( j );

  k = find ( ys < min ( 0.0, yx ) | max ( 0.0, yx ) < ys );

  plot ( [ x_min, x_max ], [0.0, 0.0], 'k-', ...
         xp, yp, 'k-', ...
         xs(i), ys(i), 'g.', ...
         xs(j), ys(j), 'r.', ...
         xs(k), ys(k), 'b.', 'LineWidth', 3, 'MarkerSize', 15 )

  area_total = ( x_max - x_min ) * ( y_max - y_min );
  area_estimate = area_total * ( pos - neg ) / n;
  area_exact = 9.0 / 16.0

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of sample points N = %d\n', n );
  fprintf ( 1, '  Area estimate = %g\n', area_estimate );
  fprintf ( 1, '  Area exact =    %g\n', area_exact );
  fprintf ( 1, '  Area error =    %g\n', abs ( area_estimate - area_exact ) );

  return
end
function value = f ( x )

  value = 0.75 * ( 1.0 - x .^ 2 );

  return
end
