Statistics

Monte Carlo

Throw random darts at a box and count the ones that land in a shape: the fraction times the box is its area. Estimate π, the area under a curve or the volume of a ball in ten dimensions, and watch the error fall like 1/√n.

hitmisserror |estimate − true|expected error ∝ 1/√n
—
—

Numbers
darts thrown n—
hits—
true value—
error now—
expected error A√(p(1−p)/n)—

What to observe

  1. Run the π estimate. The error jitters but hugs the dashed1/√n line: a hundred times more darts buys only one more digit.
  2. Area under sin x is the same recipe: box area times hit fraction. Any shape you can test a point against has an area this way.
  3. Push the ball to d = 10. It fills a quarter of a percent of the cube, so hits are rare and the error is large next to the answer, yet it still falls like 1/√n in any dimension.

Shortcuts:space run/pause · r reset · f fullscreen