% Monte Carlo estimation of the area of a circle using N points, with plot.

function a = MCCircle(N)
  x = 2*rand(1,N)-1;
  y = 2*rand(1,N)-1;
  d2 = x.^2 + y.^2;
  inside = d2 < 1;
  count = sum(inside)
  a = 4*count/N
  axis equal;
  axis([-1.2,1.2,-1.2,1.2]);
  plot([-1,1,1,-1,-1],[-1,-1,1,1,-1],'b-');
  plot(sin(2*pi*[0:100]/100),cos(2*pi*(0:100)/100),'g-');
  plot(x,y,'r*');
end

