Monte Carlo methods
The Monte Carlo method finds approximate solutions through random sampling, that is, it approximates the probability of an outcome by running multiple trails. It is a statistical technique to find an approximate answer through sampling. Let's better understand Monte Carlo intuitively with an example.
Note
Fun fact: Monte Carlo is named after Stanislaw Ulam's uncle, who often borrowed money from his relatives to gamble in a Monte Carlo casino.
Estimating the value of pi using Monte Carlo
Imagine a quadrant of a circle is placed inside a square, as shown next, and we generate some random points inside the square. You can see that some of the points fall inside the circle while others are outside the circle:
We can write:
We know that the area of a circle is πr2 and the area of a square is a2:
Let's consider that the radius of a circle is one half and the square's side is 1, so we can substitute:
Now we get the following:
The steps to estimate π are very simple:
- First, we generate...