INTERACTIVE LABORATORY / 01
Random points.
Reliable answers.
Estimate π, integrate your own function, and discover how random sampling leads to predictable answers.
Experiment settings
Try exp(-x^2), sin(alpha*x), or x^3 - beta*x. Use explicit multiplication (*). Trigonometric functions use radians.
The vertical bounds must contain the entire function. Samples are checked, but the plotted grid cannot prove a bound.
Ready. Start a simulation or add one sample.
The random experiment
QUARTER CIRCLEAverage heights
Draw X uniformly; compute f(X).
Hit or miss
Draw X and Y independently.
Add one sample to follow the same draw in both panels.
How the samples are generated
Each point is uniformly sampled in the unit square. Green points are inside the quarter circle.
Both estimates use the same n horizontal draws. Averaging heights removes the extra randomness of Y.
One run · The law of large numbers
Solid line: running estimate. Dashed line: reference. For π, the second solid line is the average-height estimator.
Many runs · Sampling distribution
Run independent repetitions to build the distribution of estimates at a fixed sample size.
Teal bars: hit-or-miss density. Orange outline: average-height density. Both use the same bins and axes; the vertical dashed line marks the reference.
UNDERSTANDING THE EXPERIMENT
Numerical integration as expectation
One realization
If X is uniform on [a, b], the average of (b−a)f(X) converges to the integral whenever f is integrable. Watch a running estimate stabilize—though temporary deviations remain possible.
Independent repetitions
Run the experiment again from new independent random draws. The spread of the estimates reveals sampling uncertainty. With finite variance, it usually decreases like 1/√n.
Why compare the methods?
For a fixed X, the chance that Y lies below the graph is (f(X)−L)/(U−L). Averaging over Y turns the hit-or-miss contribution into (b−a)f(X). Removing this extra randomness reduces variance. It does not guarantee that the average-height estimate is closer to the reference in every individual run.
The displayed reference for entered functions uses numerical quadrature, not symbolic integration. Nonintegrable or singular functions may be unsuitable for this laboratory. Every computation runs locally in your browser; no results are collected.