# Monte Carlo Approximation of Pi

Speed (iterations per frame): 1 10 100 1000 10000

Iterations (total dots): 0

Dots in Circle: 0

Approximation of Pi: 0

## What is this?

This approxmiates π using a Monte Carlo method, which is an approach to computing things by statistics and random sampling.

How would we find π using statistics? Well, we can start from formulas using π. In this demo, we happen to use a circle, which has the simplest area formula involving π. Our plan is to drop dots in random positions on a square with an inscribed circle.

Somehow, we have to leverage the count of dots inside the circle compared to the number outside circle. We know this has something to do with probability, so let just use these three symbols to start with:

• $$s$$   The side length of the square and the diameter of the circle.
• $$P(square) = 1$$   Probability the dot lands anywhere in the square, including in the circle
• $$P(circle) = \frac{A_{circle}}{A_{square}} = \frac{\pi(\frac{s}{2})^2}{s^2}$$   Does it make sense to you that the probability of landing in the circle is the area of the circle divided by the area of the square?
Now, rearranging the $$P(circle)$$ formula in terms of π gives us $\pi = 4 P(circle) = 4 \lim_{total \to \infty} \frac{in \, circle}{total}$ This is exactly what this demo does, except we stop at 10,000,000 iterations.
Created by Jason Zhao on February 24, 2018.