Estimate Pi

Monte Carlo Method

Posted by Sha Cheng on Wednesday, December 30, 2020

Area of square: $$S_s = L*L$$

Area of circle: $$S_c = Pi*(L/2)2$$

Draw random dots, with sufficient dots, the probability of dots appearing in the circle approaximately equals the area of the circle within the area of the square:

$$N_c ⁄ N_c ≈ S_c ⁄ S_s = (Pi*(L/2)2) ⁄ (L*L)$$

$$=> Pi = N_c ⁄ N_s *4 $$

Play the demo here

Code in Github