School/□ Systems Engineer/Week 29
Monte Carlo: propagate by simulation
Your model has six uncertain inputs and a square root, an exponential and an if-statement. Is there a formula for its uncertainty? You don't need one.
About 45 min · 3 goals · Checked by automated tests
1.Why should I care?
Real engineering models are messy: thresholds, lookup tables, simulations that take seconds. Monte Carlo treats the model as a black box: sample the inputs, run, collect outputs, and read the uncertainty straight off the histogram. It is how mission designers estimate landing ellipses and how this school's simulators can quantify their own uncertainty.
- ◇ Propagate input uncertainties through any computation by repeated random sampling.
- ◇ Choose a sample size from the Monte Carlo standard error, which shrinks like 1/√N.
- ◇ Report a Monte Carlo result reproducibly, with its seed, distributions and N.
2.Discover
In the Code Lab, write a function that samples V ~ N(12, 0.24²) and I ~ N(1.5, 0.06²), computes P = V·I one hundred thousand times with a fixed seed, and prints the mean and SD of P. Compare with the quadrature formula. Then replace P with a model that has a threshold (for example, a heater that switches on below 16 °C) and see the histogram the formula can't predict.
Can't use the interactive? Read a description instead
In the Code Lab, the learner writes a loop that draws random V and I from normal distributions, multiplies them, and prints the mean and standard deviation of the products. For V = 12 ± 0.24 V and I = 1.5 ± 0.06 A the formula gives P = 18 W ± about 0.80 W, and the simulation agrees closely. A model with a threshold produces a lopsided, two-humped histogram that no single ± number describes well.
3.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
When is Monte Carlo clearly preferable to the quadrature formula?
4.Apply it
Monte Carlo the rover's two-hour drive energy from the planetary-rover Build (motor power 100 ± 8 W, camera 20 ± 2 W, duration 2.0 ± 0.1 h). Report the mean, SD and a 95% percentile interval with your seed and N.
5.Understand
The algorithm
- Describe each uncertain input with a distribution (normal with its standard uncertainty is the default; uniform for a resolution limit). 2. Draw one value of every input. 3. Run the model. 4. Repeat N times. 5. Summarise the outputs: mean, SD, percentiles (the 2.5th and 97.5th give a 95% interval without assuming normality).
How big should N be?
The Monte Carlo estimate of a mean has standard error s_out/√N; estimates of an SD or of tail percentiles need more samples than estimates of a mean. A practical check: run with two different seeds. If the results differ in a digit you intend to report, increase N. For a 95% interval from percentiles, N ≥ 10,000 is a sensible start.
Correlated inputs
If two inputs share a cause (the same reference voltage, the same temperature), sample that shared cause once per trial and derive both from it. Sampling them independently would understate or overstate the output's uncertainty. This is far easier to get right in Monte Carlo than in a formula.
Reproducible randomness
Use a seeded pseudo-random generator and record the seed, the distributions, their parameters and N. Then anyone can regenerate your histogram exactly. Every simulator and practice generator on this site is seeded for exactly this reason: the server can recompute your result from the seed to check it.
Explain it another way
Instead of solving how wobbly the answer is, build a thousand slightly different worlds where each input is a bit off, run them all, and look at how much the answers disagree.
Monte Carlo propagation (GUM Supplement 1): sample x⁽ᵏ⁾ ~ p(x), compute q⁽ᵏ⁾ = f(x⁽ᵏ⁾), estimate the distribution of q empirically. Convergence O(N^−½), independent of dimension.
By the law of large numbers the sample mean of q⁽ᵏ⁾ converges to E[q]; by the central limit theorem its error is approximately N(0, Var(q)/N). The same applies to any expectation, including P(q > threshold).
Mars landing teams run thousands of simulated entries with varied atmosphere density, wind and parachute performance to draw the landing ellipse, and choose a landing site whose ellipse avoids hazards.
Worked example 1
A Monte Carlo run gives SD(P) = 0.92 W with N = 1,000, and 0.89 W with a different seed. You want to report SD to two significant figures. Is N enough?
The two seeds disagree in the second figure (0.92 vs 0.89), so no. With N = 16,000 the sampling noise drops by 4×, and repeated seeds should then agree to about ±0.01 W.
Common mix-ups
- Monte Carlo is random, so its answers can't be trusted.
✓ Its error is predictable (it shrinks as 1/√N) and seeded runs are exactly reproducible. - More inputs need exponentially more Monte Carlo samples.
✓ That is true of grid methods. Monte Carlo's convergence rate doesn't depend on the number of inputs.
6.Watch
→ Watch why sums of many random effects become bell-shaped; it explains why many Monte Carlo outputs look normal, and why some (with thresholds or products of many factors) don't.
Shows why sums and averages of many random effects drift towards a bell curve, which is what licenses the normal approximation.
31 min 14 s · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2
A Monte Carlo mean has standard error 0.08 with N = 2,500 samples. How many samples give a standard error of 0.02?
Practice 3
Which detail is essential so that someone else can reproduce your Monte Carlo result exactly?
Practice 4 · a fresh version every time
A test rig logs voltage V = 9 V (± 3%) and current I = 1.5 A (± 5%) for exactly t = 120 s, so energy E = V·I·t. Treating the two uncertainties as independent and t as exact, what is the absolute standard uncertainty of E, in joules? (3 significant figures.)
8.Predict
A Monte Carlo estimate of a standard deviation uses N = 1,000 samples. How many samples would halve its sampling noise?
Guess first. Being wrong here is how the surprise works.
9.Reflect
Concepts: Probability and Monte Carlo simulation · Propagation of uncertainty · Simulation and time stepping