{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# Integrating a simple ODE\n",
    "\n",
    "Solve the ODE dy/dt = -2y between t = 0..4, with the initial condition\n",
    "y(t=0) = 1.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 19148 characters]",
      "text/plain": [
       "<Figure size 400x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import scipy as sp\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "def f(t, y):\n",
    "    return -2 * y\n",
    "\n",
    "\n",
    "t_span = (0, 4)  # time interval\n",
    "t_eval = np.linspace(*t_span)  # times at which to evaluate `y`\n",
    "y0 = [\n",
    "    1,\n",
    "]  # initial state\n",
    "res = sp.integrate.solve_ivp(f, t_span=t_span, y0=y0, t_eval=t_eval)\n",
    "\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.plot(res.t, res.y[0])\n",
    "plt.xlabel(\"t\")\n",
    "plt.ylabel(\"y\")\n",
    "plt.title(\"Solution of Initial Value Problem\")\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
