111 KiB
Week 5 Lab — Error Propagation for Engineers and Scientists¶
In this lab, we will study how uncertainty in measured variables affects the uncertainty of computed quantities.
We will work through three parts:
- Repeated measurements and uncertainty estimation
- Propagation of uncertainty for one variable
- Propagation of uncertainty for several variables
At the end of the lab, you should be able to:
- compute the mean and sample standard deviation from repeated measurements,
- report a measurement with uncertainty,
- propagate uncertainty through simple formulas,
- identify which measured variable contributes most to the final uncertainty.
Part A — Repeated Measurements¶
In real experiments, the same quantity is often measured several times.
These repeated measurements help us estimate:
- a representative value of the quantity, using the sample mean,
- the variability of the measurements, using the sample standard deviation.
We begin with a small set of repeated voltage measurements.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
Repeated voltage measurements¶
The following values represent repeated measurements of the same voltage.
V_samples = np.array([4.98, 5.01, 5.00, 5.03, 4.99, 5.02, 4.97, 5.01])
V_samples
Compute the mean and sample standard deviation¶
We will use:
[ \bar{x} = \frac{1}{n}\sum_{i=1}^n x_i ]
and
[ s = \sqrt{\frac{1}{n-1}\sum_{i=1}^n (x_i-\bar{x})^2} ]
The mean gives a central value, while the sample standard deviation describes the spread of the repeated measurements.
V_mean = np.mean(V_samples)
V_std = np.std(V_samples, ddof=1)
print(f"Mean voltage = {V_mean:.4f} V")
print(f"Sample standard deviation = {V_std:.4f} V")
Report the measurement¶
A basic engineering report format is:
[ V \approx \bar{V} \pm s_V ]
This is a practical summary of the measured value and its variability.
print(f"Reported measurement: V = {V_mean:.4f} ± {V_std:.4f} V")
Organize the measurements in a table¶
df_voltage = pd.DataFrame({
"trial": np.arange(1, len(V_samples) + 1),
"voltage_V": V_samples
})
df_voltage
Plot the repeated measurements¶
The dashed line shows the sample mean.
This helps us visualize the spread of the measurements around the central value.
plt.figure(figsize=(8, 4))
plt.plot(df_voltage["trial"], df_voltage["voltage_V"], marker="o", linestyle="none", label="samples")
plt.axhline(V_mean, linestyle="--", linewidth=2, label=f"mean = {V_mean:.4f} V")
plt.xlabel("Trial")
plt.ylabel("Voltage [V]")
plt.title("Repeated Voltage Measurements")
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()
Exercise A¶
Using the measurements above, answer the following:
- What is the estimated voltage?
- What does the sample standard deviation tell us?
- Are the measurements relatively precise or widely scattered?
Write a short interpretation in your own words.
Part B — Propagation of Uncertainty for One Variable¶
Now we consider a quantity that is not measured directly, but computed from another measured variable.
Suppose the output quantity is:
[ A = \pi r^2 ]
If the radius (r) has uncertainty, then the area (A) also has uncertainty.
For one variable, we use the first-order propagation formula:
[ \sigma_A \approx \left|\frac{dA}{dr}\right| \sigma_r ]
Example: Area of a circle¶
Let:
- (r = 10.0) mm
- (\sigma_r = 0.2) mm
Then:
[ A = \pi r^2 ]
and
[ \frac{dA}{dr} = 2\pi r ]
So the propagated uncertainty is:
[ \sigma_A \approx |2\pi r| \sigma_r ]
r = 10.0
sigma_r = 0.2
A = np.pi * r**2
sigma_A = abs(2 * np.pi * r) * sigma_r
print(f"Radius: r = {r:.3f} ± {sigma_r:.3f} mm")
print(f"Area: A = {A:.3f} ± {sigma_A:.3f} mm^2")
Observe how the output uncertainty changes¶
We now vary the uncertainty in the radius and observe how the area uncertainty changes.
This helps us see that larger uncertainty in the input produces larger uncertainty in the output.
sigma_r_values = np.linspace(0.01, 0.5, 100)
sigma_A_values = abs(2 * np.pi * r) * sigma_r_values
plt.figure(figsize=(8, 4))
plt.plot(sigma_r_values, sigma_A_values)
plt.xlabel("Uncertainty in radius, sigma_r [mm]")
plt.ylabel("Uncertainty in area, sigma_A [mm^2]")
plt.title("Propagation of Uncertainty: A = pi r^2")
plt.grid(True, alpha=0.3)
plt.show()
Exercise B¶
Answer the following:
- If the uncertainty in radius doubles, what happens to the uncertainty in area?
- Why does the derivative appear in the propagation formula?
- For this example, is the relation between (\sigma_r) and (\sigma_A) linear?
Write a brief explanation.
Part C — Propagation of Uncertainty for Several Variables¶
Now we study a quantity that depends on more than one measured variable.
Consider resistance:
[ R = \frac{V}{I} ]
If both voltage and current are uncertain, then the resistance will also be uncertain.
For independent variables, we use:
[ \sigma_R \approx \sqrt{ \left(\frac{\partial R}{\partial V}\sigma_V\right)^2 + \left(\frac{\partial R}{\partial I}\sigma_I\right)^2 } ]
For this case:
[ \frac{\partial R}{\partial V} = \frac{1}{I}, \qquad \frac{\partial R}{\partial I} = -\frac{V}{I^2} ]
Example: Resistance from voltage and current¶
Let:
- (V = 12.0 \pm 0.2) V
- (I = 2.0 \pm 0.05) A
We first compute the resistance, and then propagate the uncertainty.
V = 12.0
sigma_V = 0.2
I = 2.0
sigma_I = 0.05
R = V / I
sigma_R = np.sqrt(
(sigma_V / I)**2 +
((V * sigma_I) / (I**2))**2
)
print(f"Voltage: V = {V:.3f} ± {sigma_V:.3f} V")
print(f"Current: I = {I:.3f} ± {sigma_I:.3f} A")
print(f"Resistance: R = {R:.3f} ± {sigma_R:.3f} ohm")
Contribution of each variable¶
The total propagated variance is the sum of separate terms.
This allows us to estimate which measurement contributes more to the final uncertainty.
That is important in engineering because it helps decide which sensor or measurement process should be improved first.
term_V = (sigma_V / I)**2
term_I = ((V * sigma_I) / (I**2))**2
total = term_V + term_I
percent_V = 100 * term_V / total
percent_I = 100 * term_I / total
print(f"Contribution from voltage uncertainty: {percent_V:.2f}%")
print(f"Contribution from current uncertainty: {percent_I:.2f}%")
Visualize the contribution of each source of uncertainty¶
labels = ["Voltage term", "Current term"]
values = [percent_V, percent_I]
plt.figure(figsize=(6, 4))
plt.bar(labels, values)
plt.ylabel("Contribution to total variance [%]")
plt.title("Which Measurement Dominates the Uncertainty?")
plt.ylim(0, 100)
plt.grid(True, axis="y", alpha=0.3)
plt.show()
Relative uncertainty¶
In many cases, it is useful to express uncertainty relative to the value itself:
[ \text{Relative uncertainty} = \frac{\sigma_R}{R} ]
This can also be written as a percentage.
relative_R = sigma_R / R
relative_R_percent = 100 * relative_R
print(f"Relative uncertainty of R = {relative_R:.4f}")
print(f"Relative uncertainty of R = {relative_R_percent:.2f}%")
Summary table¶
The following table gathers the main values computed in this lab.
summary_df = pd.DataFrame({
"quantity": ["Voltage", "Current", "Resistance", "Area"],
"value": [V, I, R, A],
"uncertainty": [sigma_V, sigma_I, sigma_R, sigma_A],
"units": ["V", "A", "ohm", "mm^2"]
})
summary_df
Exercise C¶
Use the results above to answer:
- What is the computed resistance?
- What is its propagated uncertainty?
- Which variable contributes more to the uncertainty in resistance?
- If you could improve only one instrument, would you improve the voltage measurement or the current measurement?
Justify your answer briefly.
Additional Student Exercise¶
Now modify the values below and recompute the propagated uncertainty.
Suggested values:
- (V = 9.0 \pm 0.1) V
- (I = 0.50 \pm 0.03) A
Then compare the result with the previous example.
V2 = 9.0
sigma_V2 = 0.1
I2 = 0.50
sigma_I2 = 0.03
R2 = V2 / I2
sigma_R2 = np.sqrt(
(sigma_V2 / I2)**2 +
((V2 * sigma_I2) / (I2**2))**2
)
print(f"R = {R2:.3f} ± {sigma_R2:.3f} ohm")
print(f"Relative uncertainty = {100 * sigma_R2 / R2:.2f}%")
Reflection prompt¶
Compare the two resistance examples.
- Which one has the larger relative uncertainty?
- Why?
- What role does the current measurement play in each case?
Write a short paragraph discussing your observation.
term_V2 = (sigma_V2 / I2)**2
term_I2 = ((V2 * sigma_I2) / (I2**2))**2
total2 = term_V2 + term_I2
percent_V2 = 100 * term_V2 / total2
percent_I2 = 100 * term_I2 / total2
print(f"Second example - voltage contribution: {percent_V2:.2f}%")
print(f"Second example - current contribution: {percent_I2:.2f}%")
Final Questions¶
Before finishing the lab, make sure you can answer the following:
- What is the difference between repeated-measurement variability and propagated uncertainty?
- Why is the sample standard deviation useful in experimental work?
- Why does a computed quantity inherit uncertainty from its inputs?
- Why is it useful to identify the dominant source of uncertainty?
These questions are central to experimental design and data analysis.
Conclusion¶
In this lab, you learned how to:
- estimate uncertainty from repeated measurements,
- report values with uncertainty,
- propagate uncertainty through simple formulas,
- compare uncertainty contributions from different variables.
This is one of the most practical uses of statistics in engineering and scientific measurement.