{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercises on Initial Value Problems for Ordinary Differential Equations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 1\n",
    "\n",
    "Show that for the integration case $f(t, u) = f(t)$, Euler's method is the same as the composite left-hand endpoint rule,\n",
    "as in the section [Definite Integrals, Part 2](definite-integrals-2-composite-rules.ipynb)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 2\n",
    "\n",
    "A) Verify that for the simple case where $f(t, u) = f(t)$,\n",
    "the explicit trapezoid method gives the same result as the composite trapezoid rule for integration.\n",
    "\n",
    "B) Do one step of this method for the canonical example $du/dt = ku$, $u(t_0) = u_0$.\n",
    "It will have the form $U_1 = G U_0$ where the growth factor $G$ approximates the factor $g=e^{kh}$ for the exact solution $u(t_1) = g u(t_0)$ of the ODE.\n",
    "\n",
    "C) Compare to $G=1+kh$ seen for Euler's method.\n",
    "\n",
    "D) Use the previous result to express $U_i$ in terms of $U_0=u_0$, as done for Euler's method."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 3 (a lot like Exercise 2)\n",
    "\n",
    "A) Verify that for the simple case where $f(t, u) = f(t)$,\n",
    "explicit midpoint method gives the same result as the composite midpoint rule for integration (same comment as above).\n",
    "\n",
    "B) Do one step of this method for the canonical example $du/dt = ku$, $u(t_0) = u_0$.\n",
    "It will have the form $U_1 = G U_0$ where the growth factor $G$ approximates the factor $g=e^{kh}$ for the exact solution $u(t_1) = g u(t_0)$ of the ODE.\n",
    "\n",
    "C) Compare to the growth factors $G$ seen for Euler and explicit trapezoid methods, and to the growth factor $g$ for the exact solution."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 4\n",
    "\n",
    "A) Apply Richardson extrapolation to one step of Euler's method, using the values given by step sizes $h$ and $h/2$.\n",
    "\n",
    "B) This should give a second order accurate method, so compare it to the above two methods."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 5\n",
    "\n",
    "A) Verify that for the simple case where $f(t, u) = f(t)$,\n",
    "this gives the same result as the Composite Simpson's Rule for integration.\n",
    "\n",
    "B) Do one step of this method for the canonical example $du/dt = ku$, $u(t_0) = u_0$.\n",
    "It will have the form $U_1 = G U_0$ where the growth factor $G$ approximates the factor $g=e^{kh}$ for the exact solution $u(t_1) = g u(t_0)$ of the ODE.\n",
    "\n",
    "C) Compare to the growth factors $G$ seen for previous methods, and to the growth factor $g$ for the exact solution."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 6\n",
    "\n",
    "Write a formula for $U_h$ and $e_h$ if one starts from the point $(t_i, U_i)$, so that $(t_i + h, U^h)$ is the proposed value for the next point $(t_{i+1}, U_{i+1})$ in the approximate solution — but only if $e_h$ is small enough!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 7\n",
    "\n",
    "Implement the\n",
    "[error control version of the explicit trapezoid method](ODE-IVP-5-error-control-python.ipynb#ETMEC)\n",
    "from section on\n",
    "[Error Control and Variable Step Sizes](ODE-IVP-5-error-control-python.ipynb)\n",
    "and test on the two familiar examples\n",
    "\n",
    "$$\n",
    "\\begin{split}\n",
    "du/dt &= Ku\n",
    "\\\\\n",
    "&\\text{and}\n",
    "\\\\\n",
    "du/dt &= K(\\cos(t) - u) - \\sin(t)\n",
    "\\end{split}\n",
    "$$\n",
    "\n",
    "($K=1$ is enough.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "This work is licensed under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
