{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7c5a1488",
   "metadata": {},
   "source": [
    "# PHYS 216 · Assignment 6 · Question 2(d)\n",
    "## Plotting the I–V curve of an incandescent bulb\n",
    "\n",
    "**Objective:** Learn to make a graph using NumPy and Matplotlib. The ohmic comparison is exact. The filament curve uses an **additional simple thermal-radiation model**, not data given by the assignment. We do **not** assume resistance varies linearly with voltage."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71e7602f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "V = np.linspace(0, 120, 100)\n",
    "R_hot = 144\n",
    "I_ohmic = V / R_hot"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf6f08bc",
   "metadata": {},
   "source": [
    "### Construct a model bulb curve\n",
    "\n",
    "We are given that tungsten resistance changes with temperature:  \n",
    "\n",
    "$R(T)=R_{cold}[1+\\alpha(T-20)]$.  \n",
    "\n",
    "For an illustrative **thermal model** only, assume that the filament loses power by radiation: $P\\propto T_K^4-T_{room,K}^4$. We calibrate this relation using its 100 W operating point at 2550°C. This is *not* the only possible thermal model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe62642b",
   "metadata": {},
   "outputs": [],
   "source": [
    "T = np.linspace(20, 2550, 100)  # Celsius\n",
    "R_cold = 144 / (1 + 0.0045 * (2550 - 20))\n",
    "R_bulb = R_cold * (1 + 0.0045 * (T - 20))\n",
    "\n",
    "P = 100 * ((T + 273.15)**4 - 293.15**4) / (2823.15**4 - 293.15**4)\n",
    "V_bulb = np.sqrt(P * R_bulb)\n",
    "I_bulb = np.sqrt(P / R_bulb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ede74f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot(V, I_ohmic, label=\"Ohmic resistor, 144 ohms\")\n",
    "plt.plot(V_bulb, I_bulb, label=\"Bulb: thermal model\")\n",
    "plt.xlabel(\"Voltage (V)\")\n",
    "plt.ylabel(\"Current (A)\")\n",
    "plt.title(\"Assignment 6 - Question 2(d)\")\n",
    "plt.grid(True)\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e97f183",
   "metadata": {},
   "source": [
    "**Try it:** What is the difference between a straight-line I–V graph and a curved I–V graph? The initial inrush current of about 10.3 A at 120 V is a *transient* and does not lie on the steady-state curve."
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
