C117 of 30
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C11 · Lesson 7 · Uncertainty lab

Budgets, Monte Carlo propagation and pass-fail decisions in Python

Lessons 1 to 3 built uncertainty by hand: standard uncertainties, propagation by derivatives, budgets and guard bands. Code makes all of it routine, and adds a method that needs no derivatives at all: simulate the measurement thousands of times with random inputs and look at the spread of the results. In this lab you'll convert specifications to standard uncertainties, combine a budget, propagate by Monte Carlo, and write the decision rule that turns a reading and its uncertainty into pass, fail or indeterminate.

  • The curve is a budget's combined uncertainty as one contribution x grows while the other, u1, stays fixed: u12+x2.
  • While x is less than a third of u1, it barely matters: the total rises less than 6%. Once x passes u1, it takes over.
  • This is why budgets are read from the top: improving anything but the largest term changes almost nothing.

Predict

A Monte Carlo propagation of y=x2 uses x drawn from a Gaussian with mean 0 and σ = 1. What spread does y have, and what does first-order propagation by derivatives predict?

Name it

The pieces

  • Standard uncertainties: rectangular ±a gives a/3, triangular ±a gives a/6, and an expanded uncertainty U quoted at k = 2 gives U/2.
  • A budget: uc=∑(ciui)2 and U=kuc.
  • Monte Carlo propagation: draw each input from its distribution, compute the result, repeat N times, and take the mean and standard deviation of the results. Seed the random generator so the answer is reproducible. The precision of the estimated spread improves as 1/N, so tens of thousands of trials give two or three good digits.
  • Decision rules: with expanded uncertainty U and limits L and H, a reading x is a clear pass inside [L+U,H−U], a clear fail outside [L−U,H+U], and indeterminate in between.

Worked example

Propagate R = V/I by Monte Carlo with V = 5.00 ± 0.02 V and I = 2.000 ± 0.010 mA (standard uncertainties), and compare with the derivative formula.

Show the solution
  1. Monte Carlo. Twenty thousand trials give R = 2500 Ω with a spread of 15.9 Ω.
  2. Derivative formula. uR=2500Ω×(0.02/5)2+(0.01/2)2=16.0Ω
  3. Why they agree. V/I is nearly linear over such small uncertainties; the simulation would reveal the difference if I's uncertainty were a large fraction of I.

Answer both give R = 2500 Ω, with an uncertainty of 15.9 Ω by Monte Carlo and 16.0 Ω by the formula.

Worked example

A 10 V reference must read between 9 V and 10 V, and U = 0.02 V. Classify readings of 9.97, 9.99 and 10.05 V.

Show the solution
  1. Acceptance zone. Pulling each limit in by U = 0.02 V leaves [9.02, 9.98] V.
  2. 9.97 V. It is inside [9.02, 9.98]: pass.
  3. 9.99 V. It is between 9.98 and 10.02: indeterminate, because the true value could be on either side of the limit.
  4. 10.05 V. It is above 10.02: fail.
  5. An indeterminate reading. It calls for a better measurement or a decision rule agreed in advance.

Answer 9.97 V passes, 9.99 V is indeterminate, and 10.05 V fails.

Check

A budget has a term of 1 and another 0.2 times as large. What is the combined uncertainty?

Check

Write standard_u(a, dist): the standard uncertainty for a half-width a when dist is 'rectangular' or 'triangular', or for an expanded uncertainty a at k = 2 when dist is 'normal'. Then write budget(rows): given a list of (u, c) pairs, return (uc, U) with k = 2.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write monte_carlo(f, means, sds, n, seed): draw each input from a Gaussian with the given mean and standard deviation using random.Random(seed), evaluate f n times, and return (mean, std) of the results (std with n − 1).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write decide(x, lo, hi, U): return 'pass' if x is within [lo + U, hi − U], 'fail' if it's below lo − U or above hi + U, and 'indeterminate' otherwise.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

When does Monte Carlo propagation give a different answer from propagation with derivatives, and which should be trusted?

Practice

Keep practicing

One kind of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.