GLOBAL KNOWLEDGE ARK

Physics · Article

Monte Carlo and stochastic simulation

Compare one draw with an independent average, enumerate an exact finite distribution, and follow a toy random walk while separating sampling variation, bias and reproducibility.

Previous article: Numerical solutions of partial differential equations

Back to Physics

After reading, you can

  • Specify possible outcomes, their probabilities and the quantity being estimated.
  • Distinguish a realized sample average from its model expectation.
  • Calculate an independent average’s variance with explicit finite-variance assumptions.
  • Read exact discrete probability plots without treating them as measured frequencies.
  • Build a short stochastic process from independent increments and recognize dependent states.
  • Separate a reproducible pseudorandom stream from mathematical independence and physical validation.
01

Start with four possible velocities

Imagine a supplied model that returns one of four axial velocity values: 0 m/s, 1 m/s, 2 m/s or 3 m/s. Each has probability 1/4. The axis and units stay fixed. If four independent draws give the illustrative list 0 m/s, 3 m/s, 3 m/s, 2 m/s, their average is 2 m/s. The model’s equally weighted average is 1.5 m/s. Why can these answers differ?

Monte Carlo calculation uses simulated draws from a specified probability model to estimate a quantity, such as an average or an event probability. A stochastic simulation can also generate a sequence of states according to probabilistic rules. Our small model can be enumerated exactly, so it gives a check case for understanding a method that may also be used when listing all outcomes is impractical. These probabilities and values are teaching stipulations; the illustrative list is neither an instrument record nor output from a claimed software run.

Averages, squares and units are the main preparation. Algebra, functions, graphs, and logarithms and Random and systematic uncertainty offer published preparation for those ideas and variability. This lesson introduces its finite probability notation locally. On a first reading, follow the outcomes and tables; return to the variance argument after you can explain the difference between one draw and an average.

02

State a probability model and a target

Let X denote the model’s velocity output before a particular outcome is selected. This is a random variable: each possible outcome is assigned a value. Its distribution lists those values and their probabilities. Probabilities are dimensionless, nonnegative and sum to one. Here P(X = 2 m/s) = 1/4 means that the model assigns probability 1/4 to that event; it does not require every short list of four draws to contain it once.

The expectation E[X] is the probability-weighted model average. For a finite list with values xⱼ and probabilities pⱼ, E[X] = Σ pⱼxⱼ; Σ means add over all listed outcomes. In our model μ = E[X] = (0 + 1 + 2 + 3)(m/s)/4 = 1.5 m/s. The Greek letter μ names this target. An expectation need not itself be a possible single-draw value: X cannot equal 1.5 m/s here.

A realized value or average describes one selected outcome or batch. The expectation describes the stated distribution. To estimate a different target, specify a different output to average. For example, encode an event by 1 when it occurs and 0 otherwise; its expectation is the event’s probability. A velocity mean retains units m/s, whereas such an indicator and its mean are dimensionless.

The complete supplied distribution for one velocity draw. These are model probabilities, not frequencies observed in a physical experiment.
Possible velocity XProbability
0 m/s1/4
1 m/s1/4
2 m/s1/4
3 m/s1/4
03

Average independent draws

Choose a positive integer n before drawing and define the sample mean X̄ₙ = (X₁ + … + Xₙ)/n. The subscript labels the draw. Assume the draws are mutually independent and each has the same distribution as X: independent and identically distributed, abbreviated iid. In this finite model the probability of any specified ordered n-value list is (1/4)ⁿ. Selecting with replacement means every draw still has all four possibilities; it does not mean forbidding repeated values.

Variance measures model spread through squared deviations: Var(X) = E[(X − μ)²]. Here the four squared deviations are 2.25, 0.25, 0.25 and 2.25, each with units (m/s)². Their weighted mean is σ² = 5/4 (m/s)². The symbol σ² names this variance; its nonnegative square root σ is the standard deviation and has units m/s.

For iid draws with finite variance, E[X̄ₙ] = μ and Var(X̄ₙ) = σ²/n. Expectation distributes over the sum. For variance, independence makes the cross terms between distinct centered draws have expectation zero; dividing the sum by n divides its variance by n². Thus the average is unbiased for μ under this model, and its standard deviation is σ/√n. Unbiased means its model expectation equals the target, rather than every batch giving the target.

At n = 4, the mean’s variance is 5/16 (m/s)²; at n = 16 it is 5/64 (m/s)². Quadrupling n halves the standard deviation under these assumptions. It does not promise that one particular growing batch approaches μ monotonically. The list 0, 1, 2, 3 has mean 1.5 m/s, but appending another 0 m/s changes the mean to 1.2 m/s.

04

Read an exact distribution of averages

For four iid draws there are 4⁴ = 256 equally probable ordered lists. Several lists can have the same mean. All means are k/4 m/s for integer k from 0 to 12; k is the sum of the four velocity numbers expressed in m/s. Count the lists for each mean, then divide by 256. The graph compares that complete distribution with the single-draw distribution. Its bar heights are probabilities at exact values, rather than a continuous density or observed sample counts.

Predict which plot spreads farther from 1.5 m/s, then compare them. The four-draw distribution is more concentrated in the variance sense: 5/16 instead of 5/4 (m/s)². It has more possible values, including 1.5 m/s. Its center bar has probability 44/256, while every single-draw bar has probability 1/4. Comparing just the tallest bar would miss the change in spacing and the reduction in variance.

An inclusive tolerance of 0.5 m/s means |X̄₄ − 1.5 m/s| ≤ 0.5 m/s, where the vertical lines mean absolute value. Keep means from 1 m/s through 2 m/s, including both endpoints. Their counts add to 31 + 40 + 44 + 40 + 31 = 186, giving probability 93/128. A strict tolerance < 0.5 m/s keeps only the interior three means and gives 31/64. The boundary convention changes the answer.

These are exact probabilities for a batch drawn under the supplied model, calculated before seeing that batch. They are not empirical confidence claims about a real apparatus or a fitted confidence interval for an unknown physical mean. The same algebra would not establish these probabilities if the draw law or dependence were different.

Read an exact distribution of averagesTwo discrete probability plots share horizontal velocity ticks from 0 to 3 m/s, with small display margins, and a probability axis from 0 to 0.28125. The single-draw panel has four outline bars of height 1/4 at 0, 1, 2 and 3 m/s. The four-draw mean panel has thirteen hatched bars with spacing 0.25 m/s. Their probabilities are respectively 1, 4, 10, 20, 31, 40, 44, 40, 31, 20, 10, 4 and 1 divided by 256. A dashed vertical line in each panel marks expectation 1.5 m/s. The mean’s variance is 5/16 (m/s)², compared with 5/4 (m/s)² for one draw. Bar widths are a display choice; height gives probability at a discrete value, not density or an observed frequency.
  • Single draw: outline bars

    Variance: 5/4 (m/s)²

  • Four-draw mean: hatched bars

    Variance: 5/16 (m/s)²

  • Dashed line: expectation 1.5 m/s

Bar height is probability at an exact value.

Supplied probability law; no empirical frequencies

Compare the spread around 1.5 m/s in the two panels, then use the tables to check individual probabilities. Each vertical bar represents probability at its exact horizontal value. Both panels use the same axes; widths only keep bars legible and do not turn them into a density. The four-draw mean has one quarter of the single draw’s variance under the supplied iid law. These are exact model distributions, not frequencies measured from a simulation run.

Text equivalent of the four-draw probability plot. Every ordered list has probability 1/256; each row groups all lists with the stated mean.
Mean X̄₄Number of ordered listsProbability
0 m/s11/256
0.25 m/s44/256
0.5 m/s1010/256
0.75 m/s2020/256
1 m/s3131/256
1.25 m/s4040/256
1.5 m/s4444/256
1.75 m/s4040/256
2 m/s3131/256
2.25 m/s2020/256
2.5 m/s1010/256
2.75 m/s44/256
3 m/s11/256
05

Follow a time-indexed stochastic process

Now supply a different model: a point’s signed position Sₙ along a fixed axis is defined only at times tₙ = n(0.5 s), for n = 0, …, 4. Start at S₀ = 0 m. Each increment Δₙ is either −0.2 m or +0.2 m with equal probability, and the four increments are mutually independent. The update Sₙ = Sₙ₋₁ + Δₙ makes a discrete-time stochastic process: a collection of random states indexed by time. No continuous motion between the stated times is specified.

A supplied illustrative increment list +0.2 m, +0.2 m, +0.2 m, −0.2 m produces positions 0 m, 0.2 m, 0.4 m, 0.6 m, 0.4 m. Its final position is 0.4 m. The distribution’s final expectation is instead zero: each increment has zero expectation. Its variance at the fourth step is 4(0.2 m)² = 0.16 m², and its standard deviation is 0.4 m. The zero expectation does not require every path to end at the origin.

Independent increments do not make successive positions independent. S₂ includes the first increment already present in S₁. For example, P(S₂ = 0.4 m) = 1/4. If we are told S₁ = 0.2 m, reaching 0.4 m requires only that the second increment is positive, so the conditional probability is 1/2. Conditional probability means probability after restricting to the stated information; the change here demonstrates dependence.

This walk is a fully specified teaching rule on four steps. Its units permit position and time comparisons, but they do not establish a diffusion law or actual particle behaviour. Changing the step time, step length or dependence changes the model. Applying the iid mean formula directly to its successive positions would require assumptions that this process does not supply.

06

Separate a seed from a probability assumption

A pseudorandom-number generator is an algorithm that produces a sequence from an internal state. A seed helps set that starting state. Once the algorithm, state and calls are fixed, the stream is deterministic. Statistical simulation uses such streams as a computational way to represent draws; repeating a seed does not itself prove the mathematical iid assumption.

Reproducing a stream can require more than the seed. Record the generator algorithm, software version and build, environment, initial state or seed, and the sequence of calls with their arguments and requested sizes. Compatibility guarantees are specific to the implementation. Even a change from repeated single-value calls to one array request can fall outside an implementation’s promise of identical output.

Repeating exactly the same stream checks repeatability of that computation; it is not a new independent batch. Our illustrative lists were supplied directly, and no seeded implementation is claimed to have produced them. When software is used, also check that its transformation of the stream implements the intended outcome probabilities.

07

Separate variation, bias and other errors

Sampling variation is the difference among possible batch estimates under a fixed probability model. More iid draws reduce the mean’s variance when it is finite, but dependence can invalidate that calculation. If one selected X is copied four times, their mean is still X and its variance is 5/4 (m/s)², not 5/16 (m/s)². Four stored values are not automatically four independent draws.

Bias is a difference between an estimator’s expectation and its target. Suppose every output is deliberately shifted by a fixed b = +0.1 m/s and we still target the original μ = 1.5 m/s. The shifted mean has expectation μ + b = 1.6 m/s. Its variance remains σ²/n under the original iid assumptions, but its +0.1 m/s bias persists at every n. Reducing sampling variation does not remove that fixed shift.

Arithmetic rounding, approximating a continuous model on a grid, a wrong output transformation and a physically unsuitable probability law can create further discrepancies. Their effects are not included merely by using σ/√n. In this exact finite teaching case there is no grid approximation to the velocity law and the listed rational probabilities are exact; a larger physical simulation needs its own numerical and model checks.

A standard deviation summarizes spread, rather than prescribing a universal coverage percentage. A confidence interval needs a stated construction and probability assumptions. One fictional batch or a convenient seed supplies neither an empirical coverage result nor evidence that a real system follows the model.

08

Check and record the stochastic calculation

Use a small exactly checkable case before interpreting a larger calculation. Here all single-draw probabilities sum to one; the four-draw counts sum to 256; and their weighted mean and variance reproduce 1.5 m/s and 5/16 (m/s)². Check boundary conventions and repeated-value cases as well as the center. This enumeration verifies the stated finite law, while a software implementation would need additional checks against it.

Record the physical quantity, units, outcome law, dependence assumptions, target, fixed batch size and estimator. For a process, also record the initial state, update rule and time domain. Save the realized values and reproducibility details if software generated them. Choosing a new stopping rule after seeing favourable values creates a different procedure; our fixed-n proofs do not automatically apply to that rule.

Numerical agreement with a known case is useful evidence about a calculation. Interpreting a real system also requires observations and reasons for its probability law and parameters. The next lesson, Inverse problems and Bayesian computation, considers how model parameters and information can enter inference; it is a next destination, rather than a prerequisite for the finite models here.

Worked examples

Compare a realized mean with its target

Use the supplied equal-probability velocity model and four iid draws. For the illustrative list 0 m/s, 3 m/s, 3 m/s, 2 m/s, find the realized mean, its signed error relative to μ, and the model variance of a four-draw mean.

  1. The model target is μ = (0 + 1 + 2 + 3)(m/s)/4 = 1.5 m/s. It is calculated from the distribution rather than from the illustrative list.
  2. The list sums to 8 m/s, so its mean is 2 m/s. Define signed estimate error as realized mean minus μ: 2 m/s − 1.5 m/s = +0.5 m/s.
  3. The single-draw variance is [2.25 + 0.25 + 0.25 + 2.25](m/s)²/4 = 5/4 (m/s)². Independence and identical distributions give Var(X̄₄) = (5/4)/4 (m/s)² = 5/16 (m/s)².
  4. The mean’s model standard deviation is √5/4 m/s. This is a property of all possible four-draw batches, not the absolute error 0.5 m/s of this one batch. An unbiased estimator can give a nonzero realized error.

The realized mean is 2 m/s and its signed error is +0.5 m/s. The four-draw mean’s model variance is 5/16 (m/s)² and its standard deviation is √5/4 m/s.

Count the batches inside a tolerance

For the exact four-draw distribution, find P(|X̄₄ − μ| ≤ 0.5 m/s). Compare the strict inequality and the corresponding single-draw probability.

  1. The inclusive four-draw event contains means 1 m/s, 1.25 m/s, 1.5 m/s, 1.75 m/s and 2 m/s. Their counts are 31, 40, 44, 40 and 31 out of 256 equally probable ordered lists.
  2. The count is 186, so the probability is 186/256 = 93/128. With a strict inequality, remove the two boundary counts: 124/256 = 31/64.
  3. For one X, the inclusive event contains only 1 m/s and 2 m/s. Each has probability 1/4, giving 1/2. The strict single-draw event contains none of its four possible values and therefore has probability zero.
  4. The four-draw result is more likely to lie within this particular inclusive tolerance under the supplied law. It is still not certain: its complementary probability is 1 − 93/128 = 35/128. The calculation is an exact model probability, not an interval estimated from empirical data.

The four-draw inclusive probability is 93/128; its strict counterpart is 31/64. For one draw they are 1/2 and zero. Inclusive and strict boundaries cannot be interchanged.

Count random-walk endpoints

For four independent ±0.2 m increments with probability 1/2 each, find the endpoint distribution at 2 s, its expectation and variance. Compare the probability of the supplied +,+,+,− path with the probability of its endpoint.

  1. There are 2⁴ = 16 equally probable sign lists. With j positive increments and 4 − j negative ones, S₄ = [j − (4 − j)](0.2 m). For j = 0, 1, 2, 3, 4 this gives −0.8 m, −0.4 m, 0 m, 0.4 m and 0.8 m.
  2. The respective list counts are 1, 4, 6, 4, 1. Divide each by 16 to obtain its probability. Their signed weighted sum is zero, so E[S₄] = 0 m.
  3. The weighted squared positions give Var(S₄) = [0.64 + 4(0.16) + 6(0) + 4(0.16) + 0.64]m²/16 = 0.16 m². This also follows by adding four independent increment variances of 0.04 m².
  4. The specified +,+,+,− list is one of the 16, so its probability is 1/16. Its endpoint 0.4 m can be reached by four lists, each with three positive increments, and has probability 4/16 = 1/4. A path event and an endpoint event are different.

Endpoints −0.8 m, −0.4 m, 0 m, 0.4 m, 0.8 m have probabilities 1/16, 4/16, 6/16, 4/16, 1/16. Their expectation is zero and variance 0.16 m²; the specified path has probability 1/16 while its endpoint has probability 1/4.

Try it yourself

  1. For the four-value velocity model, can one draw equal its expectation 1.5 m/s? Can a four-draw mean equal it? Find the latter event’s probability.

    Show the answer and reasoning

    One draw cannot equal 1.5 m/s. A four-draw mean can, with probability 44/256 = 11/64.

    The single-draw list contains only 0, 1, 2 and 3 m/s. A four-draw mean equals 1.5 m/s when the velocity numbers sum to 6, which occurs in 44 ordered lists. A weighted expectation need not be a single possible outcome.

  2. Under the same iid law, compare the mean variance and standard deviation at n = 4 and n = 16. Does a fourfold increase in n make every realized error four times smaller?

    Show the answer and reasoning

    The variances are 5/16 and 5/64 (m/s)². The standard deviations are √5/4 and √5/8 m/s. There is no such guarantee for each realized error.

    Variance is σ²/n, so quadrupling n quarters variance and halves its square root. This compares distributions of fixed-size batches. The supplied prefix 0, 1, 2, 3 already has zero error, while appending 0 moves its mean away from the target.

  3. Select one X from the supplied velocity law and store it in four slots. Find the stored values’ mean variance. Does the presence of four slots justify the iid formula?

    Show the answer and reasoning

    Their mean equals X and has variance 5/4 (m/s)². Four slots do not establish four independent draws.

    (X + X + X + X)/4 = X. Once one slot is known, all the others are determined. The mean’s variance is unchanged; the division by four in the independent-draw variance formula is not applicable.

  4. Shift each iid velocity output by +0.1 m/s while retaining target μ = 1.5 m/s. At n = 16, find the shifted mean’s expectation, bias and variance. Is the bias removed by averaging?

    Show the answer and reasoning

    Its expectation is 1.6 m/s, bias +0.1 m/s and variance 5/64 (m/s)². Averaging does not remove that fixed bias.

    A fixed shift adds the same b to the mean and its expectation. Centering subtracts that shift again, so variance is unchanged. The target here is explicitly the original μ; changing the target to the shifted law’s expectation would be a different question.

  5. In the four-step walk, follow +0.2 m, +0.2 m, −0.2 m, −0.2 m. List the positions and final time. Compare this path’s probability with P(S₄ = 0 m).

    Show the answer and reasoning

    Positions are 0 m, 0.2 m, 0.4 m, 0.2 m, 0 m, ending at 2 s. This path has probability 1/16; its endpoint event has probability 6/16 = 3/8.

    Add each increment at successive 0.5 s times. The specified list is one of 16 equiprobable lists. Any list with two positive and two negative increments ends at zero, and there are six such lists. No between-time motion is supplied.

  6. A computation repeats an identical pseudorandom stream under its recorded compatibility conditions. Does this establish a second independent batch, prove iid draws, or validate the real physical model? What has it checked?

    Show the answer and reasoning

    None of those conclusions follows. It checks repeatability of that recorded computational stream.

    The same algorithmic state and calls replay the same values, so the repeat is not new independent information. Distribution and dependence assumptions need their own justification, and physical validity needs relevant observations. Record the generator, calls, software and environment as well as the seed.

What to carry forward

  • A Monte Carlo target and a realized batch estimate are different objects; keep the outcome law and units explicit.
  • For fixed-size iid draws with finite variance, the sample mean has expectation μ and variance σ²/n.
  • Exact finite enumeration can check a probability plot and exposes inclusive versus strict boundary differences.
  • Independent increments can produce dependent successive states in a stochastic process.
  • Reproducibility, sampling variation, persistent bias and physical-model validity require different checks.

References

Sources for the concepts and teaching approaches in this article.

  1. ProbabilidadeLeonardo T. Rolla and Bernardo N. B. de Lima — IMPA (2026)Textbook chapterProbabilityProbability axiomsConditional probabilityIndependenceSimple random variables and expectationMoments and varianceime.usp.br
  2. Lecture 5: Stochastic Processes IMassachusetts Institute of Technology OpenCourseWare — 18.S096 (Fall 2013)Course notes · PDFocw.mit.eduRead source
  3. NumPy random-number documentationNumPy Developers — NumPy v2.5 ManualReference guideRandom samplingCompatibility policynumpy.org