HomeCVSimulations

Estimation of pi by Monte Carlo method

How does it work?

Points are generated randomly and follow a uniform distribution in the square.

Hence, the probability that a point is generated in the circle is

P=AcircleAsquare=πr2(2r)2=π4\mathcal{P} = \frac{\mathcal{A}_{circle}}{\mathcal{A}_{square}} = \frac{\pi r^2}{(2r)^2}=\frac{\pi}{4}

If we call pnp_n the proportion of points inside the circle when we have generated nn points, according to the law of large numbers the limit of 4pn4 p_n is

limn+4pn=4P=π\lim\limits_{n \to +\infty} 4 p_n = 4 \mathcal{P}=\pi

So we use 4pn4 p_n as an estimation of π\pi, and it becomes a good estimation when there are enough points.