Home About Projects Resources

Estimating Pi Using Random Numbers

Python can be a very powerful tool to understand more about the world around us. Let's apply a powerful function of Python (Random Number Generator) to help us understand more about Pi ($\pi$). Pi is an interesting mathematical constant that shows up in various areas of physics and mathmatics. Pi ($\pi$) is a mathematical constant, approx. 3.141592654. It is defined in Euclidean geometry as the ratio of a cirle's circumference to its diameter, and also has various equivalent definitions.

\[ \pi = \frac{C}{d}\]

Pi ($\pi$) is an irrational and transcendental number. This means that $\pi$ has an infinite number of digits in its decimal representation and does not settle into an infinitely repeating pattern of digits. The digits of $\pi$ have no apparnet pattern and ahve passed test for statistical randomness, including test for nomality; a number of ininite length is called normal when all possible sequences of digits (of any given length) appear equally often. The conjecture that $\pi$ is normal has not been proven or disproven. Pi is also transcendental which means that it is not the solution of any non-constant polynomial equation with rational coefficients.

Application

Let's create a square with a perimeter of 8. So, each side length would be 2 units long. Now inscribe a circle inside with a radius of 1. This circle should touch each one of the four side of the squre.

pano

Using a random number generator we'll create 75 random $(x,y)$ points on the interval $[ -1 \le x,y \le 1]$. It's important to remember that the random points must be uniformly distributed. Meaning that each point on the interval $[-1,1]$ all have the same probability. As you can see below are 75 points uniformly distributed within the square. Let's estimate pi using this method.

pano

We'll need to know what points are inside of the circle. To do this we'll use the following equation $x^2+y^2 \le r^2$. If the satisfies the equation than we know it's within the circle and we can add it to the count. Once we have all of the points counted we can then move onto estimating $\pi$. Below is the equation to help us estimate $\pi$.

\[ \frac{A_{\;points\,in\,circle}}{A_{\;points\,in\,square}} = \frac{\pi r^2}{(2r)^2} = \frac{\pi r ^2}{4r^2} = \frac{\pi}{4} \qquad \qquad \pi = \frac{4 * A_{\;points\,in\,circle}}{A_{\;points\,in\,sqaure}}\]