{ "cells": [ { "cell_type": "markdown", "id": "806857a8", "metadata": {}, "source": [ "# Week 5 Lab — Error Propagation for Engineers and Scientists\n", "\n", "In this lab, we will study how uncertainty in measured variables affects the uncertainty of computed quantities.\n", "\n", "We will work through three parts:\n", "\n", "1. **Repeated measurements and uncertainty estimation**\n", "2. **Propagation of uncertainty for one variable**\n", "3. **Propagation of uncertainty for several variables**\n", "\n", "At the end of the lab, you should be able to:\n", "\n", "- compute the mean and sample standard deviation from repeated measurements,\n", "- report a measurement with uncertainty,\n", "- propagate uncertainty through simple formulas,\n", "- identify which measured variable contributes most to the final uncertainty." ] }, { "cell_type": "markdown", "id": "243d8bd5", "metadata": {}, "source": [ "## Part A — Repeated Measurements\n", "\n", "In real experiments, the same quantity is often measured several times. \n", "These repeated measurements help us estimate:\n", "\n", "- a representative value of the quantity, using the **sample mean**,\n", "- the variability of the measurements, using the **sample standard deviation**.\n", "\n", "We begin with a small set of repeated voltage measurements." ] }, { "cell_type": "markdown", "id": "41fde6a2", "metadata": {}, "source": [ "### Repeated voltage measurements\n", "\n", "The following values represent repeated measurements of the same voltage." ] }, { "cell_type": "code", "execution_count": 2, "id": "2a424c85", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([4.98, 5.01, 5. , 5.03, 4.99, 5.02, 4.97, 5.01])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "V_samples = np.array([4.98, 5.01, 5.00, 5.03, 4.99, 5.02, 4.97, 5.01])\n", "\n", "V_samples" ] }, { "cell_type": "markdown", "id": "701cbb86", "metadata": {}, "source": [ "### Compute the mean and sample standard deviation\n", "\n", "We will use:\n", "\n", "$$\\bar{x} = \\frac{1}{n}\\sum_{i=1}^n x_i$$\n", "\n", "and\n", "\n", "$$\n", "s = \\sqrt{\\frac{1}{n-1}\\sum_{i=1}^n (x_i-\\bar{x})^2}\n", "$$\n", "\n", "The mean gives a central value, while the sample standard deviation describes the spread of the repeated measurements." ] }, { "cell_type": "code", "execution_count": null, "id": "85752039", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mean voltage = 5.0013 V\n", "Sample standard deviation = 0.0203 V\n" ] } ], "source": [ "V_mean = np.mean(V_samples)\n", "V_std = np.std(V_samples, ddof=1)\n", "\n", "print(f\"Mean voltage = {V_mean:.4f} V\")\n", "print(f\"Sample standard deviation = {V_std:.4f} V\")" ] }, { "cell_type": "markdown", "id": "36199326", "metadata": {}, "source": [ "### Report the measurement\n", "\n", "A basic engineering report format is:\n", "\n", "$$\n", "V \\approx \\bar{V} \\pm s_V\n", "$$\n", "\n", "This is a practical summary of the measured value and its variability." ] }, { "cell_type": "code", "execution_count": 6, "id": "2d3cb5e5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Reported measurement: V = 5.0013 +/- 0.0203 V\n" ] } ], "source": [ "print(f\"Reported measurement: V = {V_mean:.4f} +/- {V_std:.4f} V\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "68878355", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | trial | \n", "voltage_V | \n", "
|---|---|---|
| 0 | \n", "1 | \n", "4.98 | \n", "
| 1 | \n", "2 | \n", "5.01 | \n", "
| 2 | \n", "3 | \n", "5.00 | \n", "
| 3 | \n", "4 | \n", "5.03 | \n", "
| 4 | \n", "5 | \n", "4.99 | \n", "
| 5 | \n", "6 | \n", "5.02 | \n", "
| 6 | \n", "7 | \n", "4.97 | \n", "
| 7 | \n", "8 | \n", "5.01 | \n", "