Monte Carlo Simulation
A Monte Carlo simulation relies on repeated random sampling of objects from a distribution, and subsequent operation of then, to generate numerical results. In this simulation, we utilize random sampling of 2D points from an uniform distribution to estimate the value of pi. The circle has a unit radius, whereas the square has a length of 2 distance units. If the points are appreciably random, and if we have generated enough number of points, then:
\[ \frac{number \ of \ points \ inside \ unit \ circle}{total \ number \ of \ points} \approx \frac{Area \ of \ unit \ circle}{Total \ area} = \frac{\pi}{4} \] \[ \implies \pi \approx 4 * \left(\frac{number \ of \ points \ inside \ unit \ circle}{total \ number \ of \ points}\right) \]Note:
- After a 1000 points have been sampled, the estimated value of pi usually ranges between 3.12 and 3.16
Developed by ChanRT | Fork me at GitHub