I have written the code for the estimation of pi but I don't understand ow to put hits and misses in my coding and how to ake the code loop.
Code:
clfclear all% MC estimate of pi
n=10000x=rand([1 n])y=rand ([1 n])figure(1)for i = 1:n plot(x(i), y(i), 'b+') hold on end% plot(x, y, 'r+')
c=0s=0for i=1:n s=s+1 if x(i)^2 +y(i)^2 <=1 % inside circle
c=c+1 % hold on
else % else outside circle
plot (x(i), y(i), 'r+') end end p=c/s pi_=p*4
Best Answer