% Script to compute area of disk by Monte Carlo
% Choose (x,y) uniformly in [0,1]^2
% Count how many lie in disk x^2 + y^2 < 1
% Plot points

% N is number of points
tic;
N = 1000;
count=0;
figure; hold on; grid on;
title('Computing area of disk by Monte Carlo Method');
redx=zeros(1,N);
redy=zeros(1,N);
bluex=zeros(1,N);
bluey=zeros(1,N);
for k=1:N
x=rand;
y=rand;
r=x^2+y^2;
if r < 1
count=count+1;
redx(count)=x;
redy(count)=y;
else
bluex(k-count)=x;
bluey(k-count)=y;
end % if
end % for k
area = 4*count/N
toc
figure; hold on; grid on;
title('Computing area of circle by Monte Carlo Method');
scatter(redx,redy,'r');
scatter(bluex,bluey,'b');
toc
return