74 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.
Repeated voltage measurements¶
The following values represent repeated measurements of the same voltage.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
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")
# Table
df_voltage = pd.DataFrame({
"trial": np.arange(1, len(V_samples) + 1),
"voltage_V": V_samples
})
df_voltage
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()
# Plot the repeated measurements
#The dashed line shows the sample mean.
#This helps us visualize the spread of the measurements around the central value.
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.