Virtual laboratory/Mathematics/Probability/Estimating π with the Monte Carlo method

Estimating π with the Monte Carlo method

An extension of the topic of probability and the area of a circle. Dropping points uniformly in a square with an inscribed circle, the ratio of hits inside the circle to all draws approximates π/4 — because it is the ratio of areas: circle to square. The more draws, the better the estimate of π. The Monte Carlo method was invented by Stanisław Ulam in 1946 at Los Alamos, developed together with John von Neumann.

Estimating π with the Monte Carlo method
Mathematics · Probability · Estimating π with the Monte Carlo method (1946)
Number of random points NN80 pts
As the number of random points grows, the estimate of π…
N (points)
80
hits in circle
67
estimate of π
3.3500
error |Δ|
0.2084
🎯 Challenge: hit the estimate of π
streak: 0

I’ll give you a target value for the estimate of π — tune the number of draws N with the slider to reach it.

What just happened?

We draw points uniformly in a square of side 2 (from −1 to 1), with a circle of radius r = 1 inscribed in it. We count how many points fell inside the circle. The ratio of hits to all draws approximates the ratio of areas: the more draws, the closer to the true value.

The Monte Carlo formula:

π≈4⋅hits in circleN\pi \approx 4\cdot\frac{\text{hits in circle}}{N}

— because the area of the circle is P=πr2P=\pi r^2, and with r = 1 the area of the square is (2r)2=4(2r)^2 = 4. So the ratio of areas is exactly π/4\pi/4, and the random sampling only estimates it.

The invariant — what random sampling does NOT change:

PcirclePsquare=πr24r2=π4\frac{P_{\text{circle}}}{P_{\text{square}}} = \frac{\pi r^2}{4r^2} = \frac{\pi}{4}

This ratio is always exactly the same, independent of N — it is pure geometry. Drawing points only estimates it, with an error that shrinks as N grows (the law of large numbers).

Where did this method come from?

The idea came to Stanisław Ulam in 1946 at Los Alamos, while recovering from an illness — pondering a game of solitaire, he noticed that instead of computing the odds of card arrangements combinatorially, one could play many random games and tally the statistics. Together with John von Neumann he developed this idea into calculations of neutron diffusion during work on the hydrogen bomb. The name “Monte Carlo” was proposed by Nicholas Metropolis, after the casino in Monte Carlo, where Ulam’s uncle gambled.

What does this mean in practice?

The Monte Carlo method is a general technique: when an exact calculation is too complicated, random sampling gives a good approximation. Today it is used in physics (nuclear, particle simulations), finance (option pricing, risk), machine learning and engineering.

Why you need this for the exam:

Geometric-probability problems are computed exactly from the ratio of areas (as here: π/4), without random sampling — Monte Carlo is only a visual intuition for how to estimate such a ratio when the exact formula is unknown or too hard.

Remember: more draws ⇒ smaller estimation error, but the ratio of areas P(circle)/P(square) = π/4 has always been constant — random sampling only uncovers it.

Illustrative model · NexTutor Virtual laboratory

Enjoyed the experiment? Share it.

It's free — send it to friends from school.

Theory & formulas

Ratio of areas

A circle of radius rr inscribed in a square of side 2r2r: area of circlearea of square=πr2(2r)2=π4\frac{\text{area of circle}}{\text{area of square}}=\frac{\pi r^2}{(2r)^2}=\frac{\pi}{4}

Estimating π

Dropping points uniformly in the square, the fraction of hits inside the circle tends to π4\tfrac{\pi}{4}, so: π≈4⋅hitstotal draws\pi\approx 4\cdot\frac{\text{hits}}{\text{total draws}}

Accuracy

The error shrinks like 1N\dfrac{1}{\sqrt{N}} — four times as many draws gives roughly twice the accuracy.

Notation: rr radius, NN number of draws, π≈3.14159\pi\approx 3.14159.

Frequently asked questions

›

How does dropping random points estimate π?

The ratio of points landing inside the circle to all draws approximates π/4, because it is the ratio of the circle's area to the square's area.

›

Who invented the Monte Carlo method?

Stanisław Ulam in 1946 at Los Alamos, developed in collaboration with John von Neumann.

›

Where is the Monte Carlo method used today?

In physics, finance and machine learning — wherever an exact calculation is too complicated.

Teaching? Embed this experiment on your site.

Free widget — paste it on your school site, blog or notes. It links to the full version.

Teaching a class or tutoring? Guide students in NexTutor →