function Estimate_Pi(n)

rows=[1:n]';
r=rand(n,2);
inside=r(:,1).^2+r(:,2).^2<1;
inside=[inside inside];
outside=not(inside);
red=reshape(r(inside),sum(inside(:,1)),2);
blue=reshape(r(outside),sum(outside(:,1)),2);

hold on
plot(red(:,1),red(:,2),'r.','linewidth',3);
plot(blue(:,1),blue(:,2),'b.','linewidth',3);
set(gca,'xlim',[0 1],'ylim',[0 1]);
h=title(['Red: ' num2str(length(red)) ' Blue: ' num2str(length(blue)) ...
       ' Pi: ' num2str(4*length(red)/n) ]);
set(gca,'fontsize',14)
set(h,'fontsize',16,'fontweight','bold','interpreter','none')

eval(['print -depsc pi_' num2str(n) '.eps']);
close
