Computing π with Monte Carlo
The Monte Carlo method is a statistical technique that uses random sampling to obtain numerical results. One of its elegant applications is approximating the value of π (pi).
How it works
Imagine a square with a side length of 2, centered at the origin. Inside this square, we inscribe a circle with radius 1. The area of the square is 4, and the area of the circle is π.
If we randomly place points inside the square, the probability of a point falling inside the circle is:
Therefore, if we generate N random points and count how many fall inside the circle (let's call this count M), we can approximate π as:
The more points we generate, the more accurate our approximation becomes.
Mathematical Insight
The Monte Carlo method works because we're essentially performing numerical integration to calculate the area of a unit circle:
is the indicator function that equals 1 when a point falls inside the circle and 0 otherwise.
Interactive Simulation
Results
Total Points
0
Points Inside
0
π Approximation
—
Actual π: 3.141592653589793...
