Approximate $\pi$ using monte carlo method of radius 1. I use MATLAB to do this problem, here my code to find the approximation of $\pi$.
n = 10 %numbers of samples
x = rand ([1 n]);
y = rand ([1 n]);
c = 0; s = 0;
for i = 1:n
s = s+1;
if x(i)^2 + y(i)^2 <=1 %inside circle
c = c+1;
else % else outside circle
end
end
p = c/s
pi_approx = 4*p
err = pi - pi_approx
Here I see the same problem, but i want to use my code for solving my problem. I am stack to find the curve of error with different value of $n$, how to plot the curve ? anyone can complete this code ? (for $n = 10, 100, 1000, ...,10e8)$
Here the curve based on comment below with $n = 10.$^$(1:6)$ :
