You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 KiB

None <html lang="en"> <head> </head>

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:

  1. Repeated measurements and uncertainty estimation
  2. Propagation of uncertainty for one variable
  3. 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.

In [1]:
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.

In [2]:
V_samples = np.array([4.98, 5.01, 5.00, 5.03, 4.99, 5.02, 4.97, 5.01])

V_samples
Out[2]:
array([4.98, 5.01, 5.  , 5.03, 4.99, 5.02, 4.97, 5.01])

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.

In [3]:
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")
Mean voltage = 5.0013 V
Sample standard deviation = 0.0203 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.

In [4]:
print(f"Reported measurement: V = {V_mean:.4f} ± {V_std:.4f} V")
Reported measurement: V = 5.0013 ± 0.0203 V

Organize the measurements in a table

In [5]:
df_voltage = pd.DataFrame({
    "trial": np.arange(1, len(V_samples) + 1),
    "voltage_V": V_samples
})

df_voltage
Out[5]:
trial voltage_V
0 1 4.98
1 2 5.01
2 3 5.00
3 4 5.03
4 5 4.99
5 6 5.02
6 7 4.97
7 8 5.01

Plot the repeated measurements

The dashed line shows the sample mean.
This helps us visualize the spread of the measurements around the central value.

In [6]:
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()
No description has been provided for this image

Exercise A

Using the measurements above, answer the following:

  1. What is the estimated voltage?
  2. What does the sample standard deviation tell us?
  3. 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 ]

In [7]:
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")
Radius: r = 10.000 ± 0.200 mm
Area:   A = 314.159 ± 12.566 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.

In [8]:
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()
No description has been provided for this image

Exercise B

Answer the following:

  1. If the uncertainty in radius doubles, what happens to the uncertainty in area?
  2. Why does the derivative appear in the propagation formula?
  3. 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.

In [9]:
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")
Voltage:    V = 12.000 ± 0.200 V
Current:    I = 2.000 ± 0.050 A
Resistance: R = 6.000 ± 0.180 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.

In [10]:
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}%")
Contribution from voltage uncertainty: 30.77%
Contribution from current uncertainty: 69.23%

Visualize the contribution of each source of uncertainty

In [11]:
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()
No description has been provided for this image

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.

In [12]:
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}%")
Relative uncertainty of R = 0.0300
Relative uncertainty of R = 3.00%

Summary table

The following table gathers the main values computed in this lab.

In [13]:
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
Out[13]:
quantity value uncertainty units
0 Voltage 12.000000 0.200000 V
1 Current 2.000000 0.050000 A
2 Resistance 6.000000 0.180278 ohm
3 Area 314.159265 12.566371 mm^2

Exercise C

Use the results above to answer:

  1. What is the computed resistance?
  2. What is its propagated uncertainty?
  3. Which variable contributes more to the uncertainty in resistance?
  4. 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.

In [14]:
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}%")
R = 18.000 ± 1.098 ohm
Relative uncertainty = 6.10%

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.

In [15]:
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}%")
Second example - voltage contribution: 3.32%
Second example - current contribution: 96.68%

Final Questions

Before finishing the lab, make sure you can answer the following:

  1. What is the difference between repeated-measurement variability and propagated uncertainty?
  2. Why is the sample standard deviation useful in experimental work?
  3. Why does a computed quantity inherit uncertainty from its inputs?
  4. 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.

</html>