Second Drafts
  • Home
  • Class Notes
  • (Math) Blog
  • Interactive Apps
  • CV

Estimating π

monte-carlo
probability
visualization
Use Monte Carlo methods to estimate the value of π by randomly sampling points in a square.
Published

January 2, 2025

← Return to Apps

1,000

Loading Python environment...

Results

Sample Size: -
Points Inside: -
π Estimate: -
True π: -
Absolute Error: -
Standard Error: -

About This App

This app demonstrates a simple application of Monte Carlo simulation: estimating π by random sampling. The method works by comparing areas:

  1. Consider a unit circle (radius = 1) inscribed in a square (side = 2)
  2. The circle has area \(\pi r^2 = \pi\)
  3. The square has area \((2r)^2 = 4\)
  4. The ratio of areas is \(\frac{\pi}{4}\)

By randomly generating points uniformly in the square and counting how many fall inside the circle, we can estimate this ratio:

\[\frac{\text{points inside circle}}{\text{total points}} \approx \frac{\pi}{4}\]

Therefore:

\[\pi \approx 4 \cdot \frac{\text{points inside circle}}{\text{total points}}\]

As we increase the number of random samples, the Law of Large Numbers guarantees that our estimate converges to the true value of π.

Back to top
 

Copyright 2025, Apurva Nakade