% find pi

M=1e7;
X = -1+2*rand(M,1);
Y = -1+2*rand(M,1);
Z = X.^2 + Y.^2 < 1 ; 
p = sum(Z)/M ;
4*p 
4*sqrt(p*(1-p))/sqrt(M) 