{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# ODEs 3\n",
    "* System of equations\n",
    "* Higher order derivatives\n",
    "* Decoupled ODEs\n",
    "* Adaptive time steps"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## ODE system\n",
    "* So far we have considered $dy/dt = f(y,t)$, with one equation in one variable.\n",
    "* For a system of ODEs, we have $d\\vec{y}/{dt} = \\vec{f}(\\vec{y},t).$\n",
    "    * For example, for 2 ODEs in 2 variables:\n",
    "        $$ \\frac{dx}{dt} = g(x,z,t), $$\n",
    "        $$ \\frac{dz}{dt} = h(x,z,t).$$\n",
    "    * We can write this as \n",
    "    $$ \\frac{d\\vec{y}}{dt} = \\vec{f}(\\vec{y},t),$$\n",
    "    \n",
    "    where $x=y[0]$, $z=y[1]$, $g=f[0]$ and $h=f[1]$.\n",
    "    * Note that each rate depends (in general) on all the variables.\n",
    "    * Note, below, we'll leave off the vector arrow symbols for simplicity.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "* Explicit solution is a straightforward extension of the one equation case. Python's array functionality even allows nearly identical codes for systems of equations and for one equation.\n",
    "* Implicit solutions require solution of a linear system of equations at each step for linear ODE systems. For nonlinear ODE systems, a nonlinear system must be solved at each step.\n",
    "    * Linear:\n",
    "    $$f(y) = Ay + b,$$\n",
    "    $$ y_{k+1} = y_k + \\Delta t(Ay_{k+1}+b),$$\n",
    "    $$(I-\\Delta tA)y_{k+1} = (y_k + \\Delta tb).$$\n",
    "    This last equation has the form $By_{k+1}=c$, which is a linear system solved for $y_{k+1}$ at each step.\n",
    "        * Note, $A$ and $b$ can depend on time, which is not explicitly shown.\n",
    "    * Nonlinear:\n",
    "    $$y_{k+1} = y_k + \\Delta t f(y_{k+1},t).$$\n",
    "        * Rearrange and solve the following nonlinear system for the $y_{k+1}$ vector at each step:\n",
    "        $$ F(y_{k+1}) = y_{k+1}-y_k - \\Delta tf(y_{k+1},t) = 0.$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Example\n",
    "The following reactions are given:\n",
    "$$A + B \\rightarrow C,$$\n",
    "$$A + C \\rightarrow D.$$\n",
    "* Reactions have rate constants $k_1 = 1$ and $k_2 = 2$.\n",
    "* Let $A_0=B_0=1$ and $C_0=D_0=0$.\n",
    "* Solve to 5 seconds.\n",
    "* Species concentrations are given by the following rate equations:\n",
    "\\begin{align*}\n",
    "\\frac{dA}{dt} &= -k_1AB - k_2AC, \\\\\n",
    "\\frac{dB}{dt} &= -k_1AB,         \\\\\n",
    "\\frac{dC}{dt} &=  k_1AB - k_2AC, \\\\\n",
    "\\frac{dD}{dt} &=          k_2AC.\n",
    "\\end{align*}\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Solve this system using the fourth order RK method:\n",
    "\\begin{align*}\n",
    "y_{k+1} &= y_k + h\\left(\\frac{1}{6}S_1 + \\frac{2}{6}S_2 + \\frac{2}{6}S_3 + \\frac{1}{6}S_4\\right),\\\\\n",
    "& S_1 = f(y_k), \\\\\n",
    "& S_2 = f(y_k+\\frac{h}{2}S_1), \\\\\n",
    "& S_3 = f(y_k+\\frac{h}{2}S_2), \\\\\n",
    "& S_4 = f(y_k+hS_3). \n",
    "\\end{align*}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "import Plots as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "function odeRK4(f, y0, t)\n",
    "    ns = length(t)-1\n",
    "    y  = zeros(length(t), length(y0))\n",
    "    y[1,:] = y0\n",
    "    \n",
    "    for k in 1:ns\n",
    "        h = t[k+1] - t[k]\n",
    "        S1 = f(y[k,:],          t[k])\n",
    "        S2 = f(y[k,:]+0.5*h*S1, t[k]+0.5*h)\n",
    "        S3 = f(y[k,:]+0.5*h*S2, t[k]+0.5*h)\n",
    "        S4 = f(y[k,:]+    h*S3, t[k]+    h)\n",
    "        y[k+1,:] = y[k,:] + h/6*(S1 + 2*S2 + 2*S3 + S4)\n",
    "    end\n",
    "        \n",
    "    return y\n",
    "end;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "function rhsf(ABCD, t)\n",
    "    A = ABCD[1]\n",
    "    B = ABCD[2]\n",
    "    C = ABCD[3]\n",
    "    D = ABCD[4]\n",
    "    \n",
    "    k1 = 1\n",
    "    k2 = 2\n",
    "    \n",
    "    dAdt = -k1*A*B - k2*A*C\n",
    "    dBdt = -k1*A*B\n",
    "    dCdt =  k1*A*B - k2*A*C\n",
    "    dDdt =  k2*A*C\n",
    "    \n",
    "    return [dAdt, dBdt, dCdt, dDdt]\n",
    "end;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "ABCD_initial = [1,1,0,0]\n",
    "tend = 5\n",
    "t = LinRange(0,tend,100)\n",
    "\n",
    "ABCD = odeRK4(rhsf, ABCD_initial, t);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
       "<defs>\n",
       "  <clipPath id=\"clip820\">\n",
       "    <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip820)\" d=\"\n",
       "M0 1600 L2400 1600 L2400 0 L0 0  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip821\">\n",
       "    <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip820)\" d=\"\n",
       "M320.783 1384.3 L2352.76 1384.3 L2352.76 47.2441 L320.783 47.2441  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip822\">\n",
       "    <rect x=\"320\" y=\"47\" width=\"2033\" height=\"1338\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  378.292,1384.3 378.292,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  761.683,1384.3 761.683,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1145.07,1384.3 1145.07,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1528.46,1384.3 1528.46,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1911.86,1384.3 1911.86,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  2295.25,1384.3 2295.25,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  320.783,1384.3 2352.76,1384.3 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  378.292,1384.3 378.292,1365.4 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  761.683,1384.3 761.683,1365.4 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1145.07,1384.3 1145.07,1365.4 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1528.46,1384.3 1528.46,1365.4 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1911.86,1384.3 1911.86,1365.4 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  2295.25,1384.3 2295.25,1365.4 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip820)\" d=\"M378.292 1421.08 Q372.875 1421.08 370.132 1426.43 Q367.424 1431.74 367.424 1442.43 Q367.424 1453.09 370.132 1458.44 Q372.875 1463.75 378.292 1463.75 Q383.743 1463.75 386.451 1458.44 Q389.194 1453.09 389.194 1442.43 Q389.194 1431.74 386.451 1426.43 Q383.743 1421.08 378.292 1421.08 M378.292 1415.52 Q387.007 1415.52 391.59 1422.43 Q396.208 1429.31 396.208 1442.43 Q396.208 1455.52 391.59 1462.43 Q387.007 1469.31 378.292 1469.31 Q369.576 1469.31 364.958 1462.43 Q360.375 1455.52 360.375 1442.43 Q360.375 1429.31 364.958 1422.43 Q369.576 1415.52 378.292 1415.52 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M747.256 1462.4 L758.714 1462.4 L758.714 1422.85 L746.249 1425.35 L746.249 1418.96 L758.645 1416.46 L765.658 1416.46 L765.658 1462.4 L777.117 1462.4 L777.117 1468.3 L747.256 1468.3 L747.256 1462.4 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M1137.05 1462.4 L1161.53 1462.4 L1161.53 1468.3 L1128.62 1468.3 L1128.62 1462.4 Q1132.61 1458.27 1139.48 1451.32 Q1146.39 1444.34 1148.16 1442.33 Q1151.53 1438.54 1152.85 1435.94 Q1154.21 1433.3 1154.21 1430.77 Q1154.21 1426.63 1151.29 1424.03 Q1148.41 1421.43 1143.75 1421.43 Q1140.46 1421.43 1136.78 1422.57 Q1133.13 1423.72 1128.96 1426.04 L1128.96 1418.96 Q1133.2 1417.26 1136.88 1416.39 Q1140.56 1415.52 1143.62 1415.52 Q1151.67 1415.52 1156.46 1419.55 Q1161.25 1423.58 1161.25 1430.31 Q1161.25 1433.51 1160.04 1436.39 Q1158.86 1439.24 1155.7 1443.13 Q1154.83 1444.13 1150.18 1448.96 Q1145.53 1453.75 1137.05 1462.4 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M1534.84 1440.35 Q1539.87 1441.42 1542.68 1444.83 Q1545.53 1448.23 1545.53 1453.23 Q1545.53 1460.9 1540.25 1465.11 Q1534.98 1469.31 1525.25 1469.31 Q1521.99 1469.31 1518.52 1468.65 Q1515.08 1468.02 1511.4 1466.74 L1511.4 1459.97 Q1514.32 1461.67 1517.79 1462.54 Q1521.26 1463.4 1525.04 1463.4 Q1531.64 1463.4 1535.08 1460.8 Q1538.55 1458.2 1538.55 1453.23 Q1538.55 1448.65 1535.32 1446.08 Q1532.13 1443.47 1526.4 1443.47 L1520.36 1443.47 L1520.36 1437.71 L1526.68 1437.71 Q1531.85 1437.71 1534.59 1435.66 Q1537.34 1433.58 1537.34 1429.69 Q1537.34 1425.7 1534.49 1423.58 Q1531.68 1421.43 1526.4 1421.43 Q1523.52 1421.43 1520.22 1422.05 Q1516.92 1422.68 1512.96 1423.99 L1512.96 1417.74 Q1516.95 1416.63 1520.43 1416.08 Q1523.93 1415.52 1527.02 1415.52 Q1535.01 1415.52 1539.66 1419.17 Q1544.32 1422.78 1544.32 1428.96 Q1544.32 1433.27 1541.85 1436.25 Q1539.39 1439.2 1534.84 1440.35 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M1916.37 1422.57 L1898.66 1450.24 L1916.37 1450.24 L1916.37 1422.57 M1914.53 1416.46 L1923.35 1416.46 L1923.35 1450.24 L1930.74 1450.24 L1930.74 1456.08 L1923.35 1456.08 L1923.35 1468.3 L1916.37 1468.3 L1916.37 1456.08 L1892.97 1456.08 L1892.97 1449.31 L1914.53 1416.46 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M2280.66 1416.46 L2308.2 1416.46 L2308.2 1422.36 L2287.09 1422.36 L2287.09 1435.07 Q2288.62 1434.55 2290.14 1434.31 Q2291.67 1434.03 2293.2 1434.03 Q2301.88 1434.03 2306.95 1438.79 Q2312.02 1443.54 2312.02 1451.67 Q2312.02 1460.04 2306.81 1464.69 Q2301.6 1469.31 2292.12 1469.31 Q2288.86 1469.31 2285.46 1468.75 Q2282.09 1468.2 2278.48 1467.08 L2278.48 1460.04 Q2281.6 1461.74 2284.93 1462.57 Q2288.27 1463.4 2291.98 1463.4 Q2297.99 1463.4 2301.5 1460.24 Q2305 1457.08 2305 1451.67 Q2305 1446.25 2301.5 1443.09 Q2297.99 1439.93 2291.98 1439.93 Q2289.17 1439.93 2286.36 1440.56 Q2283.58 1441.18 2280.66 1442.5 L2280.66 1416.46 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M1335.4 1514.43 L1335.4 1529.15 L1352.95 1529.15 L1352.95 1535.77 L1335.4 1535.77 L1335.4 1563.92 Q1335.4 1570.26 1337.12 1572.07 Q1338.88 1573.87 1344.2 1573.87 L1352.95 1573.87 L1352.95 1581 L1344.2 1581 Q1334.34 1581 1330.59 1577.35 Q1326.84 1573.64 1326.84 1563.92 L1326.84 1535.77 L1320.59 1535.77 L1320.59 1529.15 L1326.84 1529.15 L1326.84 1514.43 L1335.4 1514.43 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  320.783,1346.46 2352.76,1346.46 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  320.783,1031.12 2352.76,1031.12 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  320.783,715.772 2352.76,715.772 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  320.783,400.429 2352.76,400.429 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  320.783,85.0853 2352.76,85.0853 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  320.783,1384.3 320.783,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  320.783,1346.46 339.681,1346.46 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  320.783,1031.12 339.681,1031.12 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  320.783,715.772 339.681,715.772 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  320.783,400.429 339.681,400.429 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  320.783,85.0853 339.681,85.0853 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip820)\" d=\"M153.777 1325.16 Q148.36 1325.16 145.617 1330.5 Q142.909 1335.82 142.909 1346.51 Q142.909 1357.17 145.617 1362.52 Q148.36 1367.83 153.777 1367.83 Q159.228 1367.83 161.936 1362.52 Q164.679 1357.17 164.679 1346.51 Q164.679 1335.82 161.936 1330.5 Q159.228 1325.16 153.777 1325.16 M153.777 1319.6 Q162.492 1319.6 167.075 1326.51 Q171.693 1333.39 171.693 1346.51 Q171.693 1359.6 167.075 1366.51 Q162.492 1373.39 153.777 1373.39 Q145.061 1373.39 140.443 1366.51 Q135.86 1359.6 135.86 1346.51 Q135.86 1333.39 140.443 1326.51 Q145.061 1319.6 153.777 1319.6 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M184.02 1363.56 L191.346 1363.56 L191.346 1372.38 L184.02 1372.38 L184.02 1363.56 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M221.624 1325.16 Q216.207 1325.16 213.464 1330.5 Q210.756 1335.82 210.756 1346.51 Q210.756 1357.17 213.464 1362.52 Q216.207 1367.83 221.624 1367.83 Q227.075 1367.83 229.783 1362.52 Q232.526 1357.17 232.526 1346.51 Q232.526 1335.82 229.783 1330.5 Q227.075 1325.16 221.624 1325.16 M221.624 1319.6 Q230.339 1319.6 234.922 1326.51 Q239.54 1333.39 239.54 1346.51 Q239.54 1359.6 234.922 1366.51 Q230.339 1373.39 221.624 1373.39 Q212.908 1373.39 208.29 1366.51 Q203.707 1359.6 203.707 1346.51 Q203.707 1333.39 208.29 1326.51 Q212.908 1319.6 221.624 1319.6 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M266.866 1325.16 Q261.45 1325.16 258.707 1330.5 Q255.998 1335.82 255.998 1346.51 Q255.998 1357.17 258.707 1362.52 Q261.45 1367.83 266.866 1367.83 Q272.318 1367.83 275.026 1362.52 Q277.769 1357.17 277.769 1346.51 Q277.769 1335.82 275.026 1330.5 Q272.318 1325.16 266.866 1325.16 M266.866 1319.6 Q275.582 1319.6 280.165 1326.51 Q284.783 1333.39 284.783 1346.51 Q284.783 1359.6 280.165 1366.51 Q275.582 1373.39 266.866 1373.39 Q258.151 1373.39 253.533 1366.51 Q248.95 1359.6 248.95 1346.51 Q248.95 1333.39 253.533 1326.51 Q258.151 1319.6 266.866 1319.6 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M155.27 1009.81 Q149.853 1009.81 147.11 1015.16 Q144.402 1020.47 144.402 1031.17 Q144.402 1041.83 147.11 1047.17 Q149.853 1052.49 155.27 1052.49 Q160.721 1052.49 163.429 1047.17 Q166.172 1041.83 166.172 1031.17 Q166.172 1020.47 163.429 1015.16 Q160.721 1009.81 155.27 1009.81 M155.27 1004.26 Q163.985 1004.26 168.568 1011.17 Q173.186 1018.04 173.186 1031.17 Q173.186 1044.26 168.568 1051.17 Q163.985 1058.04 155.27 1058.04 Q146.555 1058.04 141.937 1051.17 Q137.353 1044.26 137.353 1031.17 Q137.353 1018.04 141.937 1011.17 Q146.555 1004.26 155.27 1004.26 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M185.513 1048.22 L192.839 1048.22 L192.839 1057.04 L185.513 1057.04 L185.513 1048.22 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M214.158 1051.13 L238.637 1051.13 L238.637 1057.04 L205.721 1057.04 L205.721 1051.13 Q209.714 1047 216.589 1040.06 Q223.499 1033.08 225.269 1031.06 Q228.637 1027.28 229.957 1024.67 Q231.311 1022.04 231.311 1019.5 Q231.311 1015.37 228.394 1012.76 Q225.512 1010.16 220.86 1010.16 Q217.561 1010.16 213.881 1011.31 Q210.235 1012.45 206.068 1014.78 L206.068 1007.7 Q210.304 1005.99 213.985 1005.13 Q217.665 1004.26 220.721 1004.26 Q228.776 1004.26 233.568 1008.29 Q238.36 1012.31 238.36 1019.05 Q238.36 1022.24 237.144 1025.13 Q235.964 1027.97 232.804 1031.86 Q231.936 1032.87 227.283 1037.7 Q222.631 1042.49 214.158 1051.13 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M253.429 1005.2 L280.964 1005.2 L280.964 1011.1 L259.853 1011.1 L259.853 1023.81 Q261.38 1023.29 262.908 1023.04 Q264.436 1022.76 265.964 1022.76 Q274.644 1022.76 279.714 1027.52 Q284.783 1032.28 284.783 1040.4 Q284.783 1048.77 279.575 1053.42 Q274.366 1058.04 264.887 1058.04 Q261.623 1058.04 258.221 1057.49 Q254.853 1056.93 251.241 1055.82 L251.241 1048.77 Q254.366 1050.47 257.7 1051.31 Q261.033 1052.14 264.748 1052.14 Q270.755 1052.14 274.262 1048.98 Q277.769 1045.82 277.769 1040.4 Q277.769 1034.99 274.262 1031.83 Q270.755 1028.67 264.748 1028.67 Q261.936 1028.67 259.123 1029.29 Q256.346 1029.92 253.429 1031.24 L253.429 1005.2 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M153.777 694.47 Q148.36 694.47 145.617 699.817 Q142.909 705.13 142.909 715.824 Q142.909 726.484 145.617 731.831 Q148.36 737.143 153.777 737.143 Q159.228 737.143 161.936 731.831 Q164.679 726.484 164.679 715.824 Q164.679 705.13 161.936 699.817 Q159.228 694.47 153.777 694.47 M153.777 688.914 Q162.492 688.914 167.075 695.824 Q171.693 702.699 171.693 715.824 Q171.693 728.914 167.075 735.824 Q162.492 742.699 153.777 742.699 Q145.061 742.699 140.443 735.824 Q135.86 728.914 135.86 715.824 Q135.86 702.699 140.443 695.824 Q145.061 688.914 153.777 688.914 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M184.02 732.873 L191.346 732.873 L191.346 741.692 L184.02 741.692 L184.02 732.873 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M206.693 689.852 L234.228 689.852 L234.228 695.755 L213.117 695.755 L213.117 708.463 Q214.644 707.942 216.172 707.699 Q217.7 707.421 219.228 707.421 Q227.908 707.421 232.978 712.178 Q238.047 716.935 238.047 725.06 Q238.047 733.428 232.839 738.081 Q227.63 742.699 218.151 742.699 Q214.888 742.699 211.485 742.143 Q208.117 741.588 204.506 740.477 L204.506 733.428 Q207.631 735.13 210.964 735.963 Q214.297 736.796 218.012 736.796 Q224.019 736.796 227.526 733.636 Q231.033 730.477 231.033 725.06 Q231.033 719.643 227.526 716.484 Q224.019 713.324 218.012 713.324 Q215.2 713.324 212.388 713.949 Q209.61 714.574 206.693 715.893 L206.693 689.852 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M266.866 694.47 Q261.45 694.47 258.707 699.817 Q255.998 705.13 255.998 715.824 Q255.998 726.484 258.707 731.831 Q261.45 737.143 266.866 737.143 Q272.318 737.143 275.026 731.831 Q277.769 726.484 277.769 715.824 Q277.769 705.13 275.026 699.817 Q272.318 694.47 266.866 694.47 M266.866 688.914 Q275.582 688.914 280.165 695.824 Q284.783 702.699 284.783 715.824 Q284.783 728.914 280.165 735.824 Q275.582 742.699 266.866 742.699 Q258.151 742.699 253.533 735.824 Q248.95 728.914 248.95 715.824 Q248.95 702.699 253.533 695.824 Q258.151 688.914 266.866 688.914 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M155.27 379.127 Q149.853 379.127 147.11 384.474 Q144.402 389.786 144.402 400.481 Q144.402 411.14 147.11 416.488 Q149.853 421.8 155.27 421.8 Q160.721 421.8 163.429 416.488 Q166.172 411.14 166.172 400.481 Q166.172 389.786 163.429 384.474 Q160.721 379.127 155.27 379.127 M155.27 373.571 Q163.985 373.571 168.568 380.481 Q173.186 387.356 173.186 400.481 Q173.186 413.571 168.568 420.481 Q163.985 427.356 155.27 427.356 Q146.555 427.356 141.937 420.481 Q137.353 413.571 137.353 400.481 Q137.353 387.356 141.937 380.481 Q146.555 373.571 155.27 373.571 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M185.513 417.529 L192.839 417.529 L192.839 426.349 L185.513 426.349 L185.513 417.529 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M206.346 374.509 L239.679 374.509 L239.679 377.495 L220.86 426.349 L213.533 426.349 L231.242 380.411 L206.346 380.411 L206.346 374.509 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M253.429 374.509 L280.964 374.509 L280.964 380.411 L259.853 380.411 L259.853 393.12 Q261.38 392.599 262.908 392.356 Q264.436 392.078 265.964 392.078 Q274.644 392.078 279.714 396.835 Q284.783 401.592 284.783 409.717 Q284.783 418.085 279.575 422.738 Q274.366 427.356 264.887 427.356 Q261.623 427.356 258.221 426.8 Q254.853 426.244 251.241 425.133 L251.241 418.085 Q254.366 419.786 257.7 420.619 Q261.033 421.453 264.748 421.453 Q270.755 421.453 274.262 418.293 Q277.769 415.133 277.769 409.717 Q277.769 404.3 274.262 401.14 Q270.755 397.981 264.748 397.981 Q261.936 397.981 259.123 398.606 Q256.346 399.231 253.429 400.55 L253.429 374.509 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M139.992 105.103 L151.45 105.103 L151.45 65.5541 L138.985 68.0541 L138.985 61.6653 L151.381 59.1653 L158.395 59.1653 L158.395 105.103 L169.853 105.103 L169.853 111.005 L139.992 111.005 L139.992 105.103 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M184.02 102.186 L191.346 102.186 L191.346 111.005 L184.02 111.005 L184.02 102.186 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M221.624 63.7833 Q216.207 63.7833 213.464 69.1305 Q210.756 74.443 210.756 85.1374 Q210.756 95.797 213.464 101.144 Q216.207 106.457 221.624 106.457 Q227.075 106.457 229.783 101.144 Q232.526 95.797 232.526 85.1374 Q232.526 74.443 229.783 69.1305 Q227.075 63.7833 221.624 63.7833 M221.624 58.2278 Q230.339 58.2278 234.922 65.1375 Q239.54 72.0124 239.54 85.1374 Q239.54 98.2276 234.922 105.137 Q230.339 112.012 221.624 112.012 Q212.908 112.012 208.29 105.137 Q203.707 98.2276 203.707 85.1374 Q203.707 72.0124 208.29 65.1375 Q212.908 58.2278 221.624 58.2278 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M266.866 63.7833 Q261.45 63.7833 258.707 69.1305 Q255.998 74.443 255.998 85.1374 Q255.998 95.797 258.707 101.144 Q261.45 106.457 266.866 106.457 Q272.318 106.457 275.026 101.144 Q277.769 95.797 277.769 85.1374 Q277.769 74.443 275.026 69.1305 Q272.318 63.7833 266.866 63.7833 M266.866 58.2278 Q275.582 58.2278 280.165 65.1375 Q284.783 72.0124 284.783 85.1374 Q284.783 98.2276 280.165 105.137 Q275.582 112.012 266.866 112.012 Q258.151 112.012 253.533 105.137 Q248.95 98.2276 248.95 85.1374 Q248.95 72.0124 253.533 65.1375 Q258.151 58.2278 266.866 58.2278 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M15.3282 988.71 L25.1893 988.71 Q20.7911 993.433 18.6152 998.803 Q16.4393 1004.13 16.4393 1010.15 Q16.4393 1022 23.7078 1028.29 Q30.93 1034.59 44.6336 1034.59 Q58.2909 1034.59 65.5594 1028.29 Q72.7816 1022 72.7816 1010.15 Q72.7816 1004.13 70.6057 998.803 Q68.4298 993.433 64.0316 988.71 L73.8001 988.71 Q77.1334 993.618 78.8001 999.127 Q80.4667 1004.59 80.4667 1010.7 Q80.4667 1026.4 70.8835 1035.42 Q61.2539 1044.45 44.6336 1044.45 Q27.967 1044.45 18.3837 1035.42 Q8.75416 1026.4 8.75416 1010.7 Q8.75416 1004.5 10.4208 999.034 Q12.0412 993.525 15.3282 988.71 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M33.2448 954.544 Q33.2448 961.396 38.6151 965.377 Q43.9392 969.359 53.2447 969.359 Q62.5502 969.359 67.9205 965.423 Q73.2446 961.442 73.2446 954.544 Q73.2446 947.738 67.8742 943.757 Q62.5039 939.775 53.2447 939.775 Q44.0318 939.775 38.6614 943.757 Q33.2448 947.738 33.2448 954.544 M26.0226 954.544 Q26.0226 943.433 33.2448 937.09 Q40.467 930.748 53.2447 930.748 Q65.9761 930.748 73.2446 937.09 Q80.4667 943.433 80.4667 954.544 Q80.4667 965.701 73.2446 972.044 Q65.9761 978.34 53.2447 978.34 Q40.467 978.34 33.2448 972.044 Q26.0226 965.701 26.0226 954.544 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M47.828 873.526 L79.1242 873.526 L79.1242 882.044 L48.1058 882.044 Q40.7447 882.044 37.0873 884.915 Q33.43 887.785 33.43 893.526 Q33.43 900.424 37.8281 904.405 Q42.2262 908.387 49.8188 908.387 L79.1242 908.387 L79.1242 916.951 L27.2726 916.951 L27.2726 908.387 L35.3281 908.387 Q30.6522 905.331 28.3374 901.211 Q26.0226 897.044 26.0226 891.628 Q26.0226 882.692 31.5781 878.109 Q37.0873 873.526 47.828 873.526 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M29.2633 819.22 L37.2262 819.22 Q35.2355 822.832 34.2633 826.489 Q33.2448 830.1 33.2448 833.804 Q33.2448 842.091 38.5225 846.674 Q43.754 851.257 53.2447 851.257 Q62.7354 851.257 68.0131 846.674 Q73.2446 842.091 73.2446 833.804 Q73.2446 830.1 72.2723 826.489 Q71.2538 822.832 69.2631 819.22 L77.1334 819.22 Q78.8001 822.785 79.6334 826.628 Q80.4667 830.424 80.4667 834.73 Q80.4667 846.443 73.1057 853.341 Q65.7446 860.239 53.2447 860.239 Q40.5595 860.239 33.2911 853.294 Q26.0226 846.304 26.0226 834.174 Q26.0226 830.239 26.8559 826.489 Q27.643 822.739 29.2633 819.22 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M51.0688 760.054 L55.2354 760.054 L55.2354 799.221 Q64.0316 798.665 68.6613 793.943 Q73.2446 789.174 73.2446 780.702 Q73.2446 775.795 72.0409 771.211 Q70.8372 766.582 68.4298 762.045 L76.4853 762.045 Q78.4297 766.628 79.4482 771.443 Q80.4667 776.258 80.4667 781.211 Q80.4667 793.619 73.2446 800.887 Q66.0224 808.109 53.7076 808.109 Q40.9762 808.109 33.5225 801.258 Q26.0226 794.36 26.0226 782.693 Q26.0226 772.23 32.7818 766.165 Q39.4947 760.054 51.0688 760.054 M48.5688 768.573 Q41.5781 768.665 37.4114 772.508 Q33.2448 776.304 33.2448 782.6 Q33.2448 789.73 37.2725 794.035 Q41.3003 798.295 48.6151 798.943 L48.5688 768.573 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M47.828 702.971 L79.1242 702.971 L79.1242 711.49 L48.1058 711.49 Q40.7447 711.49 37.0873 714.36 Q33.43 717.23 33.43 722.971 Q33.43 729.869 37.8281 733.851 Q42.2262 737.832 49.8188 737.832 L79.1242 737.832 L79.1242 746.397 L27.2726 746.397 L27.2726 737.832 L35.3281 737.832 Q30.6522 734.776 28.3374 730.656 Q26.0226 726.49 26.0226 721.073 Q26.0226 712.138 31.5781 707.554 Q37.0873 702.971 47.828 702.971 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M12.5504 677.555 L27.2726 677.555 L27.2726 660.008 L33.8929 660.008 L33.8929 677.555 L62.0409 677.555 Q68.3835 677.555 70.189 675.842 Q71.9946 674.082 71.9946 668.758 L71.9946 660.008 L79.1242 660.008 L79.1242 668.758 Q79.1242 678.619 75.4668 682.369 Q71.7631 686.119 62.0409 686.119 L33.8929 686.119 L33.8929 692.369 L27.2726 692.369 L27.2726 686.119 L12.5504 686.119 L12.5504 677.555 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M35.2355 618.759 Q34.4022 620.194 34.0318 621.907 Q33.6151 623.573 33.6151 625.61 Q33.6151 632.833 38.3373 636.721 Q43.0132 640.564 51.8095 640.564 L79.1242 640.564 L79.1242 649.129 L27.2726 649.129 L27.2726 640.564 L35.3281 640.564 Q30.6059 637.879 28.3374 633.573 Q26.0226 629.268 26.0226 623.11 Q26.0226 622.231 26.1615 621.166 Q26.2541 620.101 26.4856 618.805 L35.2355 618.759 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M53.0595 586.259 Q53.0595 596.583 55.4206 600.564 Q57.7817 604.546 63.4761 604.546 Q68.0131 604.546 70.6983 601.583 Q73.3372 598.574 73.3372 593.435 Q73.3372 586.351 68.3372 582.092 Q63.2909 577.787 54.9576 577.787 L53.0595 577.787 L53.0595 586.259 M49.541 569.268 L79.1242 569.268 L79.1242 577.787 L71.2538 577.787 Q75.976 580.703 78.2445 585.055 Q80.4667 589.407 80.4667 595.703 Q80.4667 603.666 76.0223 608.388 Q71.5316 613.064 64.0316 613.064 Q55.2817 613.064 50.8373 607.231 Q46.3929 601.351 46.3929 589.731 L46.3929 577.787 L45.5595 577.787 Q39.6799 577.787 36.4855 581.675 Q33.2448 585.518 33.2448 592.509 Q33.2448 596.953 34.3096 601.166 Q35.3744 605.379 37.504 609.268 L29.6337 609.268 Q27.8281 604.592 26.9485 600.194 Q26.0226 595.796 26.0226 591.629 Q26.0226 580.379 31.8559 574.824 Q37.6892 569.268 49.541 569.268 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M12.5504 543.296 L27.2726 543.296 L27.2726 525.75 L33.8929 525.75 L33.8929 543.296 L62.0409 543.296 Q68.3835 543.296 70.189 541.583 Q71.9946 539.824 71.9946 534.5 L71.9946 525.75 L79.1242 525.75 L79.1242 534.5 Q79.1242 544.361 75.4668 548.111 Q71.7631 551.861 62.0409 551.861 L33.8929 551.861 L33.8929 558.111 L27.2726 558.111 L27.2726 551.861 L12.5504 551.861 L12.5504 543.296 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M27.2726 514.546 L27.2726 506.028 L79.1242 506.028 L79.1242 514.546 L27.2726 514.546 M7.08751 514.546 L7.08751 506.028 L17.8745 506.028 L17.8745 514.546 L7.08751 514.546 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M33.2448 468.111 Q33.2448 474.963 38.6151 478.945 Q43.9392 482.926 53.2447 482.926 Q62.5502 482.926 67.9205 478.991 Q73.2446 475.009 73.2446 468.111 Q73.2446 461.306 67.8742 457.324 Q62.5039 453.343 53.2447 453.343 Q44.0318 453.343 38.6614 457.324 Q33.2448 461.306 33.2448 468.111 M26.0226 468.111 Q26.0226 457 33.2448 450.658 Q40.467 444.315 53.2447 444.315 Q65.9761 444.315 73.2446 450.658 Q80.4667 457 80.4667 468.111 Q80.4667 479.269 73.2446 485.611 Q65.9761 491.907 53.2447 491.907 Q40.467 491.907 33.2448 485.611 Q26.0226 479.269 26.0226 468.111 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip820)\" d=\"M47.828 387.093 L79.1242 387.093 L79.1242 395.612 L48.1058 395.612 Q40.7447 395.612 37.0873 398.482 Q33.43 401.352 33.43 407.093 Q33.43 413.991 37.8281 417.973 Q42.2262 421.954 49.8188 421.954 L79.1242 421.954 L79.1242 430.519 L27.2726 430.519 L27.2726 421.954 L35.3281 421.954 Q30.6522 418.899 28.3374 414.778 Q26.0226 410.612 26.0226 405.195 Q26.0226 396.26 31.5781 391.676 Q37.0873 387.093 47.828 387.093 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip822)\" style=\"stroke:#009af9; stroke-linecap:round; stroke-linejoin:round; stroke-width:8; stroke-opacity:1; fill:none\" points=\"\n",
       "  378.292,85.0853 397.655,148.592 417.018,211.033 436.381,271.651 455.744,329.958 475.108,385.658 494.471,438.599 513.834,488.733 533.197,536.08 552.56,580.709 \n",
       "  571.924,622.719 591.287,662.229 610.65,699.367 630.013,734.268 649.376,767.063 668.739,797.883 688.103,826.854 707.466,854.094 726.829,879.718 746.192,903.832 \n",
       "  765.555,926.536 784.919,947.923 804.282,968.08 823.645,987.087 843.008,1005.02 862.371,1021.95 881.735,1037.94 901.098,1053.05 920.461,1067.33 939.824,1080.85 \n",
       "  959.187,1093.63 978.55,1105.74 997.914,1117.21 1017.28,1128.08 1036.64,1138.39 1056,1148.16 1075.37,1157.44 1094.73,1166.24 1114.09,1174.6 1133.46,1182.54 \n",
       "  1152.82,1190.09 1172.18,1197.26 1191.55,1204.08 1210.91,1210.57 1230.27,1216.74 1249.64,1222.61 1269,1228.2 1288.36,1233.53 1307.72,1238.6 1327.09,1243.43 \n",
       "  1346.45,1248.03 1365.81,1252.42 1385.18,1256.6 1404.54,1260.59 1423.9,1264.39 1443.27,1268.01 1462.63,1271.47 1481.99,1274.77 1501.36,1277.93 1520.72,1280.93 \n",
       "  1540.08,1283.8 1559.45,1286.54 1578.81,1289.16 1598.17,1291.66 1617.54,1294.04 1636.9,1296.32 1656.26,1298.5 1675.63,1300.58 1694.99,1302.57 1714.35,1304.47 \n",
       "  1733.71,1306.29 1753.08,1308.02 1772.44,1309.68 1791.8,1311.27 1811.17,1312.78 1830.53,1314.23 1849.89,1315.62 1869.26,1316.94 1888.62,1318.21 1907.98,1319.42 \n",
       "  1927.35,1320.58 1946.71,1321.69 1966.07,1322.75 1985.44,1323.77 2004.8,1324.74 2024.16,1325.67 2043.53,1326.55 2062.89,1327.4 2082.25,1328.22 2101.62,1329 \n",
       "  2120.98,1329.74 2140.34,1330.45 2159.7,1331.13 2179.07,1331.79 2198.43,1332.41 2217.79,1333.01 2237.16,1333.58 2256.52,1334.13 2275.88,1334.65 2295.25,1335.16 \n",
       "  \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#e26f46; stroke-linecap:round; stroke-linejoin:round; stroke-width:8; stroke-opacity:1; fill:none\" points=\"\n",
       "  378.292,85.0853 397.655,145.681 417.018,200.476 436.381,250.071 455.744,295.018 475.108,335.818 494.471,372.919 513.834,406.72 533.197,437.576 552.56,465.799 \n",
       "  571.924,491.665 591.287,515.416 610.65,537.267 630.013,557.407 649.376,576.002 668.739,593.201 688.103,609.133 707.466,623.917 726.829,637.655 746.192,650.438 \n",
       "  765.555,662.351 784.919,673.466 804.282,683.85 823.645,693.562 843.008,702.656 862.371,711.181 881.735,719.179 901.098,726.691 920.461,733.753 939.824,740.397 \n",
       "  959.187,746.653 978.55,752.549 997.914,758.11 1017.28,763.357 1036.64,768.313 1056,772.997 1075.37,777.425 1094.73,781.615 1114.09,785.582 1133.46,789.339 \n",
       "  1152.82,792.899 1172.18,796.274 1191.55,799.476 1210.91,802.514 1230.27,805.399 1249.64,808.138 1269,810.74 1288.36,813.213 1307.72,815.565 1327.09,817.801 \n",
       "  1346.45,819.929 1365.81,821.953 1385.18,823.88 1404.54,825.715 1423.9,827.463 1443.27,829.128 1462.63,830.714 1481.99,832.226 1501.36,833.667 1520.72,835.041 \n",
       "  1540.08,836.352 1559.45,837.602 1578.81,838.794 1598.17,839.932 1617.54,841.018 1636.9,842.055 1656.26,843.044 1675.63,843.989 1694.99,844.891 1714.35,845.752 \n",
       "  1733.71,846.575 1753.08,847.361 1772.44,848.112 1791.8,848.829 1811.17,849.515 1830.53,850.17 1849.89,850.796 1869.26,851.394 1888.62,851.967 1907.98,852.513 \n",
       "  1927.35,853.036 1946.71,853.536 1966.07,854.014 1985.44,854.472 2004.8,854.909 2024.16,855.327 2043.53,855.727 2062.89,856.109 2082.25,856.475 2101.62,856.825 \n",
       "  2120.98,857.16 2140.34,857.481 2159.7,857.787 2179.07,858.081 2198.43,858.361 2217.79,858.63 2237.16,858.887 2256.52,859.133 2275.88,859.368 2295.25,859.593 \n",
       "  \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#3da44d; stroke-linecap:round; stroke-linejoin:round; stroke-width:8; stroke-opacity:1; fill:none\" points=\"\n",
       "  378.292,1346.46 397.655,1288.77 417.018,1241.62 436.381,1203.05 455.744,1171.47 475.108,1145.57 494.471,1124.31 513.834,1106.84 533.197,1092.47 552.56,1080.65 \n",
       "  571.924,1070.93 591.287,1062.94 610.65,1056.38 630.013,1051 649.376,1046.6 668.739,1043.03 688.103,1040.13 707.466,1037.8 726.829,1035.95 746.192,1034.5 \n",
       "  765.555,1033.38 784.919,1032.53 804.282,1031.92 823.645,1031.51 843.008,1031.25 862.371,1031.13 881.735,1031.12 901.098,1031.21 920.461,1031.37 939.824,1031.6 \n",
       "  959.187,1031.87 978.55,1032.19 997.914,1032.54 1017.28,1032.91 1036.64,1033.3 1056,1033.71 1075.37,1034.13 1094.73,1034.55 1114.09,1034.98 1133.46,1035.41 \n",
       "  1152.82,1035.83 1172.18,1036.25 1191.55,1036.67 1210.91,1037.08 1230.27,1037.48 1249.64,1037.88 1269,1038.27 1288.36,1038.64 1307.72,1039.01 1327.09,1039.37 \n",
       "  1346.45,1039.72 1365.81,1040.05 1385.18,1040.38 1404.54,1040.7 1423.9,1041.01 1443.27,1041.3 1462.63,1041.59 1481.99,1041.87 1501.36,1042.13 1520.72,1042.39 \n",
       "  1540.08,1042.64 1559.45,1042.88 1578.81,1043.11 1598.17,1043.34 1617.54,1043.55 1636.9,1043.76 1656.26,1043.96 1675.63,1044.15 1694.99,1044.33 1714.35,1044.51 \n",
       "  1733.71,1044.68 1753.08,1044.84 1772.44,1045 1791.8,1045.15 1811.17,1045.3 1830.53,1045.44 1849.89,1045.57 1869.26,1045.7 1888.62,1045.82 1907.98,1045.94 \n",
       "  1927.35,1046.05 1946.71,1046.16 1966.07,1046.27 1985.44,1046.37 2004.8,1046.46 2024.16,1046.56 2043.53,1046.64 2062.89,1046.73 2082.25,1046.81 2101.62,1046.89 \n",
       "  2120.98,1046.96 2140.34,1047.04 2159.7,1047.1 2179.07,1047.17 2198.43,1047.23 2217.79,1047.29 2237.16,1047.35 2256.52,1047.41 2275.88,1047.46 2295.25,1047.51 \n",
       "  \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip822)\" style=\"stroke:#c271d2; stroke-linecap:round; stroke-linejoin:round; stroke-width:8; stroke-opacity:1; fill:none\" points=\"\n",
       "  378.292,1346.46 397.655,1343.55 417.018,1335.9 436.381,1324.88 455.744,1311.52 475.108,1296.62 494.471,1280.78 513.834,1264.45 533.197,1247.95 552.56,1231.55 \n",
       "  571.924,1215.41 591.287,1199.65 610.65,1184.36 630.013,1169.6 649.376,1155.4 668.739,1141.78 688.103,1128.74 707.466,1116.28 726.829,1104.39 746.192,1093.06 \n",
       "  765.555,1082.27 784.919,1072 804.282,1062.23 823.645,1052.93 843.008,1044.09 862.371,1035.69 881.735,1027.7 901.098,1020.1 920.461,1012.88 939.824,1006.01 \n",
       "  959.187,999.478 978.55,993.266 997.914,987.357 1017.28,981.735 1036.64,976.385 1056,971.294 1075.37,966.449 1094.73,961.835 1114.09,957.442 1133.46,953.258 \n",
       "  1152.82,949.272 1172.18,945.475 1191.55,941.857 1210.91,938.408 1230.27,935.12 1249.64,931.986 1269,928.997 1288.36,926.146 1307.72,923.427 1327.09,920.833 \n",
       "  1346.45,918.358 1365.81,915.996 1385.18,913.741 1404.54,911.589 1423.9,909.534 1443.27,907.572 1462.63,905.699 1481.99,903.91 1501.36,902.201 1520.72,900.568 \n",
       "  1540.08,899.008 1559.45,897.518 1578.81,896.094 1598.17,894.733 1617.54,893.433 1636.9,892.19 1656.26,891.001 1675.63,889.865 1694.99,888.779 1714.35,887.741 \n",
       "  1733.71,886.748 1753.08,885.799 1772.44,884.891 1791.8,884.022 1811.17,883.192 1830.53,882.397 1849.89,881.638 1869.26,880.911 1888.62,880.215 1907.98,879.55 \n",
       "  1927.35,878.914 1946.71,878.305 1966.07,877.722 1985.44,877.164 2004.8,876.631 2024.16,876.12 2043.53,875.632 2062.89,875.164 2082.25,874.717 2101.62,874.289 \n",
       "  2120.98,873.879 2140.34,873.486 2159.7,873.111 2179.07,872.751 2198.43,872.407 2217.79,872.078 2237.16,871.763 2256.52,871.461 2275.88,871.172 2295.25,870.896 \n",
       "  \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip820)\" d=\"\n",
       "M2034.33 480.613 L2285.02 480.613 L2285.02 91.8126 L2034.33 91.8126  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:0; fill:none\" points=\"\n",
       "  2034.33,480.613 2285.02,480.613 2285.02,91.8126 2034.33,91.8126 2034.33,480.613 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip820)\" style=\"stroke:#009af9; stroke-linecap:round; stroke-linejoin:round; stroke-width:12; stroke-opacity:1; fill:none\" points=\"\n",
       "  2056.9,169.573 2192.37,169.573 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip820)\" d=\"M2238.7 150.562 L2229.18 176.361 L2248.24 176.361 L2238.7 150.562 M2234.74 143.653 L2242.69 143.653 L2262.45 195.493 L2255.15 195.493 L2250.43 182.194 L2227.06 182.194 L2222.34 195.493 L2214.95 195.493 L2234.74 143.653 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip820)\" style=\"stroke:#e26f46; stroke-linecap:round; stroke-linejoin:round; stroke-width:12; stroke-opacity:1; fill:none\" points=\"\n",
       "  2056.9,247.333 2192.37,247.333 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip820)\" d=\"M2221.96 248.496 L2221.96 267.489 L2233.21 267.489 Q2238.87 267.489 2241.58 265.162 Q2244.32 262.801 2244.32 257.975 Q2244.32 253.114 2241.58 250.822 Q2238.87 248.496 2233.21 248.496 L2221.96 248.496 M2221.96 227.176 L2221.96 242.801 L2232.34 242.801 Q2237.48 242.801 2239.98 240.892 Q2242.52 238.947 2242.52 234.989 Q2242.52 231.065 2239.98 229.121 Q2237.48 227.176 2232.34 227.176 L2221.96 227.176 M2214.95 221.413 L2232.86 221.413 Q2240.88 221.413 2245.22 224.746 Q2249.56 228.079 2249.56 234.225 Q2249.56 238.982 2247.34 241.794 Q2245.12 244.607 2240.81 245.301 Q2245.99 246.412 2248.83 249.954 Q2251.72 253.461 2251.72 258.739 Q2251.72 265.683 2246.99 269.468 Q2242.27 273.253 2233.56 273.253 L2214.95 273.253 L2214.95 221.413 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip820)\" style=\"stroke:#3da44d; stroke-linecap:round; stroke-linejoin:round; stroke-width:12; stroke-opacity:1; fill:none\" points=\"\n",
       "  2056.9,325.093 2192.37,325.093 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip820)\" d=\"M2256.75 303.166 L2256.75 310.561 Q2253.21 307.263 2249.18 305.631 Q2245.19 303.999 2240.68 303.999 Q2231.79 303.999 2227.06 309.45 Q2222.34 314.867 2222.34 325.145 Q2222.34 335.388 2227.06 340.839 Q2231.79 346.256 2240.68 346.256 Q2245.19 346.256 2249.18 344.624 Q2253.21 342.992 2256.75 339.693 L2256.75 347.02 Q2253.07 349.52 2248.94 350.77 Q2244.84 352.02 2240.26 352.02 Q2228.49 352.02 2221.72 344.832 Q2214.95 337.61 2214.95 325.145 Q2214.95 312.645 2221.72 305.457 Q2228.49 298.235 2240.26 298.235 Q2244.91 298.235 2249.01 299.485 Q2253.14 300.7 2256.75 303.166 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip820)\" style=\"stroke:#c271d2; stroke-linecap:round; stroke-linejoin:round; stroke-width:12; stroke-opacity:1; fill:none\" points=\"\n",
       "  2056.9,402.853 2192.37,402.853 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip820)\" d=\"M2221.96 382.696 L2221.96 423.009 L2230.43 423.009 Q2241.16 423.009 2246.13 418.148 Q2251.13 413.287 2251.13 402.801 Q2251.13 392.384 2246.13 387.558 Q2241.16 382.696 2230.43 382.696 L2221.96 382.696 M2214.95 376.933 L2229.36 376.933 Q2244.43 376.933 2251.47 383.217 Q2258.52 389.467 2258.52 402.801 Q2258.52 416.203 2251.44 422.488 Q2244.36 428.773 2229.36 428.773 L2214.95 428.773 L2214.95 376.933 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /></svg>\n"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plt.resetfontsizes(); plt.scalefontsizes(1.5)\n",
    "plt.plot(t,ABCD, lw=2, label=[\"A\" \"B\" \"C\" \"D\"])\n",
    "plt.plot!(foreground_color_legend=nothing)\n",
    "plt.plot!(xlabel=\"t\", ylabel=\"Concentration\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Higher order derivatives\n",
    "* A single higher order ODE results in a system of first order ODEs.\n",
    "$$y^{\\prime\\prime\\prime}=\\frac{d^3y}{dt^3} = f(y,y^{\\prime},y^{\\prime\\prime},t).$$\n",
    "\n",
    "Question: can we solve this using the techniques we have used for first order ODE's? If so, how?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Can you convert this one third-order equation to a system of three first-order equations?\n",
    "\n",
    "$$y^{\\prime\\prime\\prime}=\\frac{d^3y}{dt^3} = f(y,y^{\\prime},y^{\\prime\\prime},t).$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "* let $x=y^{\\prime\\prime}$, then $y^{\\prime\\prime\\prime}=x^{\\prime}$.\n",
    "* let $z=y^{\\prime}$, then $y^{\\prime\\prime}=z^{\\prime}$.\n",
    "* Then the resulting system of ODEs is:\n",
    "\n",
    "\\begin{align}\n",
    "x^{\\prime} &= \\frac{dx}{dt} = f(y,z,x,t), \\\\\n",
    "y^{\\prime} &= \\frac{dy}{dt} = z, \\\\\n",
    "z^{\\prime} &= \\frac{dz}{dt} = x.\n",
    "\\end{align}\n",
    "\n",
    "* This is a system of three first order ODEs in three variables. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Decoupled equations\n",
    "\n",
    "* Consider a linear system of ODEs.\n",
    "$$y^{\\prime} = Ay+b.$$\n",
    "\n",
    "* In general, each rate equation depends on all the variables. \n",
    "\n",
    "* In our linear algebra review, we discussed how to decouple a system of linear equations.\n",
    "    * How did we do that?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "* To decouple the system, change to an eigenvector basis so that each component equation depends only on its own variable (in the new basis) \n",
    "* Let $V$ be a matrix whose columns are the eigenvectors of matrix $A$.\n",
    "* Let $\\Lambda$ be a diagonal matrix whose diagonal elements are the eigenvalues of $A$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "* Then,\n",
    "\n",
    "$$AV = V\\Lambda,$$\n",
    "$$A = V\\Lambda V^{-1}.$$\n",
    "\n",
    "* Insert this into the ODE:\n",
    "$$y^{\\prime} = V\\Lambda V^{-1}y + b.$$\n",
    "* Multiply through by $V^{-1}$:\n",
    "$$(V^{-1}y^{\\prime}) = \\Lambda(V^{-1}y) + (V^{-1}b).$$\n",
    "* Now, let $\\hat{y}=V^{-1}y$, and $\\hat{b}=V^{-1}b$:\n",
    "$$\\hat{y}^{\\prime} = \\Lambda \\hat{y} + \\hat{b}.$$\n",
    "* Because $\\Lambda$ is diagonal, this system is decoupled. That is component $i$ is given by\n",
    "$$\\hat{y}^{\\prime}_i = \\lambda_i\\hat{y}_i + \\hat{b}_i.$$\n",
    "* This equation has a simple analytic solution.\n",
    "    * When solved, all the $\\hat{y}_i(t)$ are known. \n",
    "    * Then $y(t)$ are given by\n",
    "    $$y(t) = V\\hat{y}(t).$$\n",
    "    \n",
    "This analysis can be useful for solving ODEs analytically, but also for analyzing (and modifying) stability properties of ODEs."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## ODE Step Size\n",
    "* See [Numerical Recipes](http://s3.amazonaws.com/nrbook.com/book_C210.html) section 16.2 for more detailed explanations.\n",
    "* When solving an ODE, we needed a step size $\\Delta t$ or $h$.\n",
    "* How should we select the step size?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Consider integrating $dy/dt = \\tanh(t)$\n",
    "* What part of the solution will dictate the step size?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "* Do we have to use this step size everywhere?\n",
    "* If not, how can we make the computer choose the stepsize in an \"intelligent\" way?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Suppose we know the error $\\Delta$ for a given step size $\\Delta t=h_1$.\n",
    "* We'll show how to get $\\Delta$ below.\n",
    "\n",
    "Suppose we set some desired error that we are okay with on a given step, like $|\\Delta|\\le\\epsilon = atol + |y|rtol.$ \n",
    "* A large $y\\rightarrow$ rtol controls; \n",
    "* A small $y\\rightarrow$ atol controls.\n",
    "\n",
    "Given a known error for a known step, how can we change our step to get the desired error? Assume we are using the RK4 method.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Adjust $h$ to get the desired error.\n",
    "* For a globally $4^{th}$ order method $\\rightarrow$ $\\Delta = \\mathcal{O}(h^5)$ $\\rightarrow$ $\\Delta\\sim h^5$.\n",
    "* Then \n",
    "$$\\frac{\\Delta_2}{\\Delta_1} = \\frac{\\epsilon}{\\Delta_1} = \\left(\\frac{h_2}{h_1}\\right)^5,$$\n",
    "<font color='blue'>\n",
    "$$\\rightarrow h_2 = h_1\\left(\\frac{\\epsilon}{\\Delta_1}\\right)^{1/5}.$$\n",
    "</font>\n",
    "* So, guess an initial $h_1$.\n",
    "    * If the error $\\Delta_1$ is too big, then redo the step using a smaller $h$ as computed using the above equation.\n",
    "    * If the error is too small, take the step, but do the *next* step with a larger $h$ computed using the equation above."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### How to compute $\\Delta$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "* See N.R.\n",
    "* Two approaches:\n",
    "    1. Step doubling\n",
    "    2. Felberg.\n",
    "    \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "#### Step doubling\n",
    "\n",
    "\n",
    "* Consider two grids where we can either take two size $h$ steps, or one size $2h$ step:\n",
    "``` \n",
    "(A)   <----h---->|<----h---->\n",
    "(B)   <---------2h---------->\n",
    "```\n",
    "* Now, let $\\Delta$ = $y_B-y_A$.\n",
    "    * Recall, if the error of the method (per step) is $\\mathcal{O}(h^5)$, then \n",
    "        \n",
    "        \\begin{align}\n",
    "        y_{exact} &= y_A + 2\\mathcal{O}(h^5), \\\\\n",
    "        y_{exact} &= y_B + \\mathcal{O}((2h)^5) = y_B + 32\\mathcal{O}(h^5).\n",
    "        \\end{align}\n",
    "    * The error in $y_{B}$ is 16 times larger than the error in $y_{A}$, so we consider $y_A$ to be exact (compared to $y_B$), and evaluate $\\Delta = y_B-y_A$. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "* ***Cost*** \n",
    "    * Each RK step requires 4 function evaluations.\n",
    "    * 3 total steps (two for grid (A) and one for grid (B)) $\\rightarrow$ 12 function evaluations. Actually 11, since the grids share a starting point.\n",
    "    * We compare 11 required using step doubling to 8 required without step doubling.\n",
    "    * <font color='blue'>37.5%=(11-8)/8 is the cost increase.</font>\n",
    "    * This cost increase pays for itself in terms of allowing (ideally) at least 37.5% fewer overall steps due to the adaptive stepsize control.\n",
    "        * For a given error, without adaptive stepsize, the *whole* time domain would have to use the most stringent step size.\n",
    "   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "#### [Felberg](https://onlinelibrary.wiley.com/doi/abs/10.1002/zamm.19660460102)\n",
    "\n",
    "* You can write an RK method where one linear combination of slopes results in an $\\mathcal{O}(h^6)$ method, and another combination of the same slopes gives an $\\mathcal{O}(h^5)$ method.\n",
    "\n",
    "\\begin{align}\n",
    "y_{k+1}       &= y_k + h(a_1S_1 + a_2S_2 + a_3S_3 + a_4S_4 + a_5S_5 + a_6S_6 ) + \\mathcal{O}(h^6),\\\\\n",
    "\\hat{y}_{k+1} &= y_k + h(b_1S_1 + b_2S_2 + b_3S_3 + b_4S_4 + b_5S_5 + b_6S_6 ) + \\mathcal{O}(h^5).\n",
    "\\end{align}\n",
    "\n",
    "* Then let $\\Delta=y_{k+1}-\\hat{y}_{k+1}$.\n",
    "\n",
    "[See Hoffman](https://ignite.byu.edu/cbe541/lectures/felberg.pdf)"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Julia 1.8.3",
   "language": "julia",
   "name": "julia-1.8"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.8.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
