Estimate Value of π

How to estimate value of π through simulation
Simulation
Author

Sushobhon Karmakar

Published

July 25, 2025

Introduction

The number π, representing the ratio of a circle’s circumference to its diameter, is one of the most famous and mysterious constants in mathematics. Its value—approximately 3.14159—has fascinated mathematicians for thousands of years. Ancient civilizations like the Babylonians and Egyptians made some of the earliest approximations of π using simple geometric techniques. Later, Greek mathematician Archimedes developed a more accurate method by inscribing and circumscribing polygons around a circle, laying the groundwork for more precise calculations.

Over centuries, mathematicians continued to refine the value of π using increasingly complex analytical techniques. But today, with the power of computers and a bit of creativity, we can estimate π using probabilistic simulations—a method that’s both intuitive and surprisingly effective.

In this blog, we’ll explore how simulation, especially the Monte Carlo method, can be used to estimate π. Whether you’re a math enthusiast or just curious about how randomness can reveal deep truths, this post will guide you through the concepts and code needed to approximate π using simple experiments.

Estimating π Through Simulation

The animation below, made with Shiny, will make easier to understand by giving geometrical sense.

Consider a Square with side 2 unit and a circle inside the square with radius 1. Now, Area of the circle is 2 \times 2 = 4 and the area of the circle inside is \pi r^2 = \pi 1^2 = \pi.

Now, if we generate a random 2d points in (0, 2) \times (0, 2) space from Uniform(0,2) the the chance of the point falling inside the circle P is

P = \frac{\text{Area of Circle}}{\text{Area of Square}}\\\\ = \frac{\pi}{4} Hence, \pi = P \times 4

Now we need to estimate P.

We estimate P through simulation. We will generate suppose n random numbers pairs from U(0, 2) and count how many random number pairs are falling inside the circle. The we count the number of pounts falling inside the circle, suppose p, out of total n. So, P = \frac{p}{n}

As we increase the value of n we can see the estimate of \pi will move close to 3.14..