{
  "cells": [
    {
      "cell_type": "markdown",
      "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",
      "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": "code",
      "execution_count": 1,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "import matplotlib.pyplot as plt"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Repeated voltage measurements\n",
        "\n",
        "The following values represent repeated measurements of the same voltage."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "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": [
        "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",
      "metadata": {},
      "source": [
        "### Compute the mean and sample standard deviation\n",
        "\n",
        "We will use:\n",
        "\n",
        "\\[\n",
        "\\bar{x} = \\frac{1}{n}\\sum_{i=1}^n x_i\n",
        "\\]\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": 3,
      "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",
      "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": 4,
      "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": "markdown",
      "metadata": {},
      "source": [
        "### Organize the measurements in a table"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>trial</th>\n",
              "      <th>voltage_V</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>4.98</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>5.01</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>5.00</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>5.03</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>4.99</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>6</td>\n",
              "      <td>5.02</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>7</td>\n",
              "      <td>4.97</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>8</td>\n",
              "      <td>5.01</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   trial  voltage_V\n",
              "0      1       4.98\n",
              "1      2       5.01\n",
              "2      3       5.00\n",
              "3      4       5.03\n",
              "4      5       4.99\n",
              "5      6       5.02\n",
              "6      7       4.97\n",
              "7      8       5.01"
            ]
          },
          "execution_count": 5,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "df_voltage = pd.DataFrame({\n",
        "    \"trial\": np.arange(1, len(V_samples) + 1),\n",
        "    \"voltage_V\": V_samples\n",
        "})\n",
        "\n",
        "df_voltage"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Plot the repeated measurements\n",
        "\n",
        "The dashed line shows the sample mean.  \n",
        "This helps us visualize the spread of the measurements around the central value."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "image/png": "[encoded data, 28668 characters]",
            "text/plain": [
              "<Figure size 800x400 with 1 Axes>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "plt.figure(figsize=(8, 4))\n",
        "plt.plot(df_voltage[\"trial\"], df_voltage[\"voltage_V\"], marker=\"o\", linestyle=\"none\", label=\"samples\")\n",
        "plt.axhline(V_mean, linestyle=\"--\", linewidth=2, label=f\"mean = {V_mean:.4f} V\")\n",
        "plt.xlabel(\"Trial\")\n",
        "plt.ylabel(\"Voltage [V]\")\n",
        "plt.title(\"Repeated Voltage Measurements\")\n",
        "plt.legend()\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Exercise A\n",
        "\n",
        "Using the measurements above, answer the following:\n",
        "\n",
        "1. What is the estimated voltage?\n",
        "2. What does the sample standard deviation tell us?\n",
        "3. Are the measurements relatively precise or widely scattered?\n",
        "\n",
        "Write a short interpretation in your own words."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Part B — Propagation of Uncertainty for One Variable\n",
        "\n",
        "Now we consider a quantity that is not measured directly, but computed from another measured variable.\n",
        "\n",
        "Suppose the output quantity is:\n",
        "\n",
        "\\[\n",
        "A = \\pi r^2\n",
        "\\]\n",
        "\n",
        "If the radius \\(r\\) has uncertainty, then the area \\(A\\) also has uncertainty.\n",
        "\n",
        "For one variable, we use the first-order propagation formula:\n",
        "\n",
        "\\[\n",
        "\\sigma_A \\approx \\left|\\frac{dA}{dr}\\right| \\sigma_r\n",
        "\\]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Example: Area of a circle\n",
        "\n",
        "Let:\n",
        "\n",
        "- \\(r = 10.0\\) mm\n",
        "- \\(\\sigma_r = 0.2\\) mm\n",
        "\n",
        "Then:\n",
        "\n",
        "\\[\n",
        "A = \\pi r^2\n",
        "\\]\n",
        "\n",
        "and\n",
        "\n",
        "\\[\n",
        "\\frac{dA}{dr} = 2\\pi r\n",
        "\\]\n",
        "\n",
        "So the propagated uncertainty is:\n",
        "\n",
        "\\[\n",
        "\\sigma_A \\approx |2\\pi r| \\sigma_r\n",
        "\\]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Radius: r = 10.000 ± 0.200 mm\n",
            "Area:   A = 314.159 ± 12.566 mm^2\n"
          ]
        }
      ],
      "source": [
        "r = 10.0\n",
        "sigma_r = 0.2\n",
        "\n",
        "A = np.pi * r**2\n",
        "sigma_A = abs(2 * np.pi * r) * sigma_r\n",
        "\n",
        "print(f\"Radius: r = {r:.3f} ± {sigma_r:.3f} mm\")\n",
        "print(f\"Area:   A = {A:.3f} ± {sigma_A:.3f} mm^2\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Observe how the output uncertainty changes\n",
        "\n",
        "We now vary the uncertainty in the radius and observe how the area uncertainty changes.\n",
        "\n",
        "This helps us see that larger uncertainty in the input produces larger uncertainty in the output."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "image/png": "[encoded data, 35760 characters]",
            "text/plain": [
              "<Figure size 800x400 with 1 Axes>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "sigma_r_values = np.linspace(0.01, 0.5, 100)\n",
        "sigma_A_values = abs(2 * np.pi * r) * sigma_r_values\n",
        "\n",
        "plt.figure(figsize=(8, 4))\n",
        "plt.plot(sigma_r_values, sigma_A_values)\n",
        "plt.xlabel(\"Uncertainty in radius, sigma_r [mm]\")\n",
        "plt.ylabel(\"Uncertainty in area, sigma_A [mm^2]\")\n",
        "plt.title(\"Propagation of Uncertainty: A = pi r^2\")\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Exercise B\n",
        "\n",
        "Answer the following:\n",
        "\n",
        "1. If the uncertainty in radius doubles, what happens to the uncertainty in area?\n",
        "2. Why does the derivative appear in the propagation formula?\n",
        "3. For this example, is the relation between \\(\\sigma_r\\) and \\(\\sigma_A\\) linear?\n",
        "\n",
        "Write a brief explanation."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Part C — Propagation of Uncertainty for Several Variables\n",
        "\n",
        "Now we study a quantity that depends on more than one measured variable.\n",
        "\n",
        "Consider resistance:\n",
        "\n",
        "\\[\n",
        "R = \\frac{V}{I}\n",
        "\\]\n",
        "\n",
        "If both voltage and current are uncertain, then the resistance will also be uncertain.\n",
        "\n",
        "For independent variables, we use:\n",
        "\n",
        "\\[\n",
        "\\sigma_R \\approx \\sqrt{\n",
        "\\left(\\frac{\\partial R}{\\partial V}\\sigma_V\\right)^2 +\n",
        "\\left(\\frac{\\partial R}{\\partial I}\\sigma_I\\right)^2\n",
        "}\n",
        "\\]\n",
        "\n",
        "For this case:\n",
        "\n",
        "\\[\n",
        "\\frac{\\partial R}{\\partial V} = \\frac{1}{I},\n",
        "\\qquad\n",
        "\\frac{\\partial R}{\\partial I} = -\\frac{V}{I^2}\n",
        "\\]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Example: Resistance from voltage and current\n",
        "\n",
        "Let:\n",
        "\n",
        "- \\(V = 12.0 \\pm 0.2\\) V\n",
        "- \\(I = 2.0 \\pm 0.05\\) A\n",
        "\n",
        "We first compute the resistance, and then propagate the uncertainty."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Voltage:    V = 12.000 ± 0.200 V\n",
            "Current:    I = 2.000 ± 0.050 A\n",
            "Resistance: R = 6.000 ± 0.180 ohm\n"
          ]
        }
      ],
      "source": [
        "V = 12.0\n",
        "sigma_V = 0.2\n",
        "\n",
        "I = 2.0\n",
        "sigma_I = 0.05\n",
        "\n",
        "R = V / I\n",
        "\n",
        "sigma_R = np.sqrt(\n",
        "    (sigma_V / I)**2 +\n",
        "    ((V * sigma_I) / (I**2))**2\n",
        ")\n",
        "\n",
        "print(f\"Voltage:    V = {V:.3f} ± {sigma_V:.3f} V\")\n",
        "print(f\"Current:    I = {I:.3f} ± {sigma_I:.3f} A\")\n",
        "print(f\"Resistance: R = {R:.3f} ± {sigma_R:.3f} ohm\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Contribution of each variable\n",
        "\n",
        "The total propagated variance is the sum of separate terms.  \n",
        "This allows us to estimate which measurement contributes more to the final uncertainty.\n",
        "\n",
        "That is important in engineering because it helps decide which sensor or measurement process should be improved first."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Contribution from voltage uncertainty: 30.77%\n",
            "Contribution from current uncertainty: 69.23%\n"
          ]
        }
      ],
      "source": [
        "term_V = (sigma_V / I)**2\n",
        "term_I = ((V * sigma_I) / (I**2))**2\n",
        "total = term_V + term_I\n",
        "\n",
        "percent_V = 100 * term_V / total\n",
        "percent_I = 100 * term_I / total\n",
        "\n",
        "print(f\"Contribution from voltage uncertainty: {percent_V:.2f}%\")\n",
        "print(f\"Contribution from current uncertainty: {percent_I:.2f}%\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Visualize the contribution of each source of uncertainty"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "image/png": "[encoded data, 22068 characters]",
            "text/plain": [
              "<Figure size 600x400 with 1 Axes>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "labels = [\"Voltage term\", \"Current term\"]\n",
        "values = [percent_V, percent_I]\n",
        "\n",
        "plt.figure(figsize=(6, 4))\n",
        "plt.bar(labels, values)\n",
        "plt.ylabel(\"Contribution to total variance [%]\")\n",
        "plt.title(\"Which Measurement Dominates the Uncertainty?\")\n",
        "plt.ylim(0, 100)\n",
        "plt.grid(True, axis=\"y\", alpha=0.3)\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Relative uncertainty\n",
        "\n",
        "In many cases, it is useful to express uncertainty relative to the value itself:\n",
        "\n",
        "\\[\n",
        "\\text{Relative uncertainty} = \\frac{\\sigma_R}{R}\n",
        "\\]\n",
        "\n",
        "This can also be written as a percentage."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Relative uncertainty of R = 0.0300\n",
            "Relative uncertainty of R = 3.00%\n"
          ]
        }
      ],
      "source": [
        "relative_R = sigma_R / R\n",
        "relative_R_percent = 100 * relative_R\n",
        "\n",
        "print(f\"Relative uncertainty of R = {relative_R:.4f}\")\n",
        "print(f\"Relative uncertainty of R = {relative_R_percent:.2f}%\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Summary table\n",
        "\n",
        "The following table gathers the main values computed in this lab."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>quantity</th>\n",
              "      <th>value</th>\n",
              "      <th>uncertainty</th>\n",
              "      <th>units</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Voltage</td>\n",
              "      <td>12.000000</td>\n",
              "      <td>0.200000</td>\n",
              "      <td>V</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Current</td>\n",
              "      <td>2.000000</td>\n",
              "      <td>0.050000</td>\n",
              "      <td>A</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Resistance</td>\n",
              "      <td>6.000000</td>\n",
              "      <td>0.180278</td>\n",
              "      <td>ohm</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Area</td>\n",
              "      <td>314.159265</td>\n",
              "      <td>12.566371</td>\n",
              "      <td>mm^2</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "     quantity       value  uncertainty units\n",
              "0     Voltage   12.000000     0.200000     V\n",
              "1     Current    2.000000     0.050000     A\n",
              "2  Resistance    6.000000     0.180278   ohm\n",
              "3        Area  314.159265    12.566371  mm^2"
            ]
          },
          "execution_count": 13,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "summary_df = pd.DataFrame({\n",
        "    \"quantity\": [\"Voltage\", \"Current\", \"Resistance\", \"Area\"],\n",
        "    \"value\": [V, I, R, A],\n",
        "    \"uncertainty\": [sigma_V, sigma_I, sigma_R, sigma_A],\n",
        "    \"units\": [\"V\", \"A\", \"ohm\", \"mm^2\"]\n",
        "})\n",
        "\n",
        "summary_df"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Exercise C\n",
        "\n",
        "Use the results above to answer:\n",
        "\n",
        "1. What is the computed resistance?\n",
        "2. What is its propagated uncertainty?\n",
        "3. Which variable contributes more to the uncertainty in resistance?\n",
        "4. If you could improve only one instrument, would you improve the voltage measurement or the current measurement?\n",
        "\n",
        "Justify your answer briefly."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Additional Student Exercise\n",
        "\n",
        "Now modify the values below and recompute the propagated uncertainty.\n",
        "\n",
        "Suggested values:\n",
        "\n",
        "- \\(V = 9.0 \\pm 0.1\\) V\n",
        "- \\(I = 0.50 \\pm 0.03\\) A\n",
        "\n",
        "Then compare the result with the previous example."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "R = 18.000 ± 1.098 ohm\n",
            "Relative uncertainty = 6.10%\n"
          ]
        }
      ],
      "source": [
        "V2 = 9.0\n",
        "sigma_V2 = 0.1\n",
        "\n",
        "I2 = 0.50\n",
        "sigma_I2 = 0.03\n",
        "\n",
        "R2 = V2 / I2\n",
        "sigma_R2 = np.sqrt(\n",
        "    (sigma_V2 / I2)**2 +\n",
        "    ((V2 * sigma_I2) / (I2**2))**2\n",
        ")\n",
        "\n",
        "print(f\"R = {R2:.3f} ± {sigma_R2:.3f} ohm\")\n",
        "print(f\"Relative uncertainty = {100 * sigma_R2 / R2:.2f}%\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Reflection prompt\n",
        "\n",
        "Compare the two resistance examples.\n",
        "\n",
        "- Which one has the larger relative uncertainty?\n",
        "- Why?\n",
        "- What role does the current measurement play in each case?\n",
        "\n",
        "Write a short paragraph discussing your observation."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Second example - voltage contribution: 3.32%\n",
            "Second example - current contribution: 96.68%\n"
          ]
        }
      ],
      "source": [
        "term_V2 = (sigma_V2 / I2)**2\n",
        "term_I2 = ((V2 * sigma_I2) / (I2**2))**2\n",
        "total2 = term_V2 + term_I2\n",
        "\n",
        "percent_V2 = 100 * term_V2 / total2\n",
        "percent_I2 = 100 * term_I2 / total2\n",
        "\n",
        "print(f\"Second example - voltage contribution: {percent_V2:.2f}%\")\n",
        "print(f\"Second example - current contribution: {percent_I2:.2f}%\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Final Questions\n",
        "\n",
        "Before finishing the lab, make sure you can answer the following:\n",
        "\n",
        "1. What is the difference between repeated-measurement variability and propagated uncertainty?\n",
        "2. Why is the sample standard deviation useful in experimental work?\n",
        "3. Why does a computed quantity inherit uncertainty from its inputs?\n",
        "4. Why is it useful to identify the dominant source of uncertainty?\n",
        "\n",
        "These questions are central to experimental design and data analysis."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Conclusion\n",
        "\n",
        "In this lab, you learned how to:\n",
        "\n",
        "- estimate uncertainty from repeated measurements,\n",
        "- report values with uncertainty,\n",
        "- propagate uncertainty through simple formulas,\n",
        "- compare uncertainty contributions from different variables.\n",
        "\n",
        "This is one of the most practical uses of statistics in engineering and scientific measurement."
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": ".venv (3.14.2)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
