{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Populating the interactive namespace from numpy and matplotlib\n"
     ]
    }
   ],
   "source": [
    "%pylab inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas\n",
    "import sympy as Ω\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from scipy.misc import derivative\n",
    "import pickle\n",
    "from tqdm import tqdm_notebook as tqdm\n",
    "\n",
    "from dataclasses import dataclass\n",
    "\n",
    "import scipy.sparse\n",
    "import scipy.sparse.linalg\n",
    "\n",
    "import functools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ω.init_printing()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "i, k = Ω.symbols('i k')\n",
    "I, K = Ω.symbols('I K')\n",
    "h_x, h_t = Ω.symbols('h_x h_t')\n",
    "l, T, H, D = Ω.symbols('l T H D')\n",
    "\n",
    "u = Ω.IndexedBase('u', shape=(I + 1, K + 1))\n",
    "\n",
    "gamma = Ω.symbols('gamma')\n",
    "gamma_val = D * h_t / h_x**2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## простейшая неявная повышенного порядка аппроксимации"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4864 characters]\n",
      "text/latex": [
       "$$\\left [ - \\gamma {u}_{k,i + 1} - \\gamma {u}_{k,i - 1} + 2 \\gamma {u}_{k,i} - {u}_{k - 1,i} + {u}_{k,i}, \\quad - H {u}_{k,0} + \\frac{- {u}_{k,-1} + {u}_{k,1}}{2 h_{x}}, \\quad H {u}_{k,I} + \\frac{{u}_{k,I + 1} - {u}_{k,I - 1}}{2 h_{x}}\\right ]$$"
      ],
      "text/plain": [
       "⎡                                                                             \n",
       "⎢-γ⋅u[k, i + 1] - γ⋅u[k, i - 1] + 2⋅γ⋅u[k, i] - u[k - 1, i] + u[k, i], -H⋅u[k,\n",
       "⎣                                                                             \n",
       "\n",
       "      -u[k, -1] + u[k, 1]              u[k, I + 1] - u[k, I - 1]⎤\n",
       " 0] + ───────────────────, H⋅u[k, I] + ─────────────────────────⎥\n",
       "              2⋅hₓ                                2⋅hₓ          ⎦"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eqs = [\n",
    "    (u[k, i] - u[k - 1, i]) / h_t - D * (u[k, i + 1] - 2 * u[k, i] + u[k, i - 1]) / (h_x**2),\n",
    "    (u[k, 1] - u[k, -1]) / (2 * h_x) - H * u[k, 0],\n",
    "    (u[k, I+1] - u[k, I - 1]) / (2 * h_x) + H * u[k, I],\n",
    "]\n",
    "eqs[0] = (eqs[0] * h_t).expand().subs({gamma_val:gamma})\n",
    "eqs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $i=1,I-1$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZEAAAAZCAYAAADwtRNWAAAABHNCSVQICAgIfAhkiAAABr1JREFUeJztnXuoFFUYwH+Gpdcr+EhCTMzM1CTwlhlKEWtZEr3Miv4oaKkoIQuJKLKXlmRQUBZRVMgtEiwUKwtMIU0tyleSpWZaa+Qjk+whGmrd/vjO0tzZ2TtnZs88dvf7wWV2vvOY833nnDnvuaAoiqIoiqJkzpvAAaA164TkgLFAB3Bn1glRFEWpB8YB/wL3++SnIi/SJcBO4CjwB7AWuAM4KcU01sKNwEvAGuBPpIF4OyTMEmAf0DvZpCmKotQ/y4HfgRaffBrywt0LLADmAvON3w5gEdAtvWTGZjOS3r+Abdg1IhcafzOTTZ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cpf2jqmRYUtk2hEdiI7R24CrkIWAL8K8HcMOBk5wFSmFTnNe66594drQ3pxU5Ae2evArXQeKlejHNa/X7+RUNunTwewGhgADK/i5zFkwXQjMoV10DJu2/zMM+PNdaVH1gzlL20d06LClv41ERccQ7a2DUd6W49W8fcxsld6NbLS3xupYF8jvbteyCKilzYkU+Yju1Q+jZCuMVSf+51J508z9EBeDg94ZFci3w3KM/Vo+znAIyHhJwKrIjwvbRYjp84nIy9+L7cBTyKNwRpkUd1PieDFbdv8TIMp5g9k2gVkU0G7+X2QzvWlzBWI7u97ZHkqf0mRtI5Z1ZvUbLmU8JX/nsgQfS8yPNqADPP6Iq3cqoAw25HDVUeQU71R2IF8xyiI/khFLf8tBl70yfzfRPKThzURqD/bD0CG/l399QqJP8s1EYBTkJ02QWc6ZhG+y2dVF3Hb5KcNRWrTcRZd61AKCNMH6UW/55PnqfwlRdI6ZlVvUrPlWqT3EaZEFHqZOMcBtyAGON8ybKsJOz7Mo6Gd+lxYh/q3fRzyYPvyJy7OcxxvEvmZFvciNrm4xnjyXv5cUIuOcYlab1KzZTfkS59bHcc7HllkKo8InkL2Op9uEXYC0SpiO3aNSG9kCNqG9B4eN7+HWD7HNY1ge1vyZvueyCLqUodxJpWfadCC9MIXOYgrj+XPNbXoGIVa6k1qtiyf4F3gON5pyOGsMt2Ad5HFyrJSRfPsoQFht2NPO3aNSAE3h7dc0Qi2t6VAvmwPcpDrCdz9U6qk8jMNzkHq0FAHceWx/LnGRkcXFAivN0UytuXNVC5Kp8Vs4FuS2TBQD6jtG4ss87Pe0PLnjqa25XrcHKZSoqO2V7JEy5871JaKoiiKoiiKoiiKoiiKoiiKoig+/gMWSRDG0okCugAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$- \\gamma {u}_{k,i + 1} - \\gamma {u}_{k,i - 1} + \\left(2 \\gamma + 1\\right) {u}_{k,i} - {u}_{k - 1,i}$$"
      ],
      "text/plain": [
       "-γ⋅u[k, i + 1] - γ⋅u[k, i - 1] + (2⋅γ + 1)⋅u[k, i] - u[k - 1, i]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(eqs[0]).collect([\n",
    "    u[k, i-1],\n",
    "    u[k, i],\n",
    "    u[k, i+1],\n",
    "    u[k-1, i-1],\n",
    "    u[k-1, i],\n",
    "    u[k-1, i+1],\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $i=0$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAAZCAYAAADEzNJKAAAABHNCSVQICAgIfAhkiAAACMJJREFUeJztnXusHkUZh59WPLY9h3DRKEEDtVxaGiOn1CoINqeIiH94A0yjJrgCUazVVOMFFbFooyYatRDijRAkYMDQVG2McEjkjpZeRaVVRA5GSkUQlQoihfrHb9az3TO7Ozt7+fZ83zxJs+eb2868M+9c3pnZQiAQCAQCgb7hB8CjwHCvM1KSjwH7gPf0OiOBXBajejq/1xkJ9B8vRg1rPfBH4Gngn8CdwHnAzN5lrW9YAjwPfDzl7iv7cdQhjOW88zsmzAd8M224xqSzoGI6bdEv7fls4DLgDuBfqA6uKYizHngEGGk2a4FB4wLUAHcB1wJfAa4E/mHcbwBm9Cx3/cE4kufslLuv7B8H9pK/Ktlm0jihSsaB+4AnmT6da7+05+0ov08CO3AbJF5rwn222awFBo1TgbcytRM4DPgzanRntZ2pDhFRPGvP41i0iviexc9H9vOM+69z3jkHeBb4D/DC8ln+P8PAc2gW3jYRfnLvUnuO8G87y4Bj0IA2htsgARpQHmL6DOqBhqizAfwC2IA6siS7kckCpjbyd6JOaCNwZEa6l7C/ueMz5veZlrBHGL/1JfI9XTgXKfr1Fj8f2b/GPDfmvHMxcABwL6on8KuzUdTWtgILUSe1G9gD3A28LicPvaKt9tw0twD3m3eW4TqkT2+y+A2qDg5kuduaJcQdzN6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X/7pGE7Jpi+OQiWpuTem56GFEtg6Czu5PoMMWW7B/KqRruPY/VRmjuI+K6AP5LkeFsG2gNc0lwO9o5ztW/UQv66zrBNmUI+hgswT5VmQT08uUEQj0G0EHmyXINxAIBAKBQCAQCAQCgUAgEAgEAoFA5/kfts2VtLTPe5kAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$- 2 \\gamma {u}_{k,1} + \\left(2 H \\gamma h_{x} + 2 \\gamma + 1\\right) {u}_{k,0} - {u}_{k - 1,0}$$"
      ],
      "text/plain": [
       "-2⋅γ⋅u[k, 1] + (2⋅H⋅γ⋅hₓ + 2⋅γ + 1)⋅u[k, 0] - u[k - 1, 0]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solution = Ω.solve(eqs[0].subs({i:0}), u[k, -1])[0]\n",
    "(-eqs[1]*2*h_x*gamma).subs({u[k, -1]: solution}).expand().collect([\n",
    "    u[k, 0],\n",
    "    u[k, 1],\n",
    "])\n",
    "# (-eqs[1] * h_x * 2 * gamma_val).subs({u[k, -1]: solution}).expand().collect([\n",
    "#     u[k, 0],\n",
    "#     u[k, 1],\n",
    "# ])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $i=I$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAAAZCAYAAAD5XrMsAAAABHNCSVQICAgIfAhkiAAACNRJREFUeJztnX2MH0UZxz+tWNveEV40QMDQ0gKtDcFraxUCaa4VUf4QFJoQNcEVjKBUUokviAhFG9Fo1MIfiiEECRAwNFUbE6xR3lFobSsgrQHkMFIKUhGpIFIsf3xnc3t7s7uzs2+/u998kmbvNzM7O/PM88zOPDOzhUAgEAgEAoEa+SnwPDDQdUE8+AKwD/h41wUJZLIYtdGnuy5IYGLxdqQ064EngFeBl4D7gPOAqd0VLZDDEuD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L2+pdlN1oDsPEO1JHm/ZtZkH/XM5VpyPVjO6i4mnLteY4JyzuAd5JJc09BuYp0IZ5yX5sRvx3NmtLrDcvRmZw3qPbNsQh/ua/G305cbMSViGq6s5r8Ooyk0h+AXDk/t+RV1q6hmm3n2XVTNF3HrvqjLmTpzH3I2Isq7spMk98S4BNIYGU6kqOQcSyvqTw2qr5U6iD+dMTCooQtUrcugHaLvYQ+TbMOjRwnGk3IpS0+j/Ts5BryqmLbbdh1HVTtv3wo2x/1tCynoJHlYzXmeQLyQcdf3/0m2ot9hOP9K5DA0lsxqzKIprVDaARyufn7yJqf48p0tHi4oaPnp2lCF2ahEeLl5vdxaHQ4XOMzmqYJubTFDCT/22vKr4ptN2XXdVO1/3KlSn/U07KMD83dXGOeFyA3SMwU4GfI/5cc6UXm2bNT919F9sG6KgxTz4GzOlkKXEFv/CdddevCwUgP0q6y28g/pNlrNGEjbfEu5C6bXVN+LrYd0a5d141r/1WVYYr7o4gJKMuzUaHTC3ttcCXwZ9r5DlqgmC51oZcJcilHsOv6CLIsySYmlhskEAgUE+y6PoIsA4FAIBAIBAKBQCAQCAQCgUAgEAgEauZNirCK+XpZVgkAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$- 2 \\gamma {u}_{k,I - 1} + \\left(2 H \\gamma h_{x} + 2 \\gamma + 1\\right) {u}_{k,I} - {u}_{k - 1,I}$$"
      ],
      "text/plain": [
       "-2⋅γ⋅u[k, I - 1] + (2⋅H⋅γ⋅hₓ + 2⋅γ + 1)⋅u[k, I] - u[k - 1, I]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solution = Ω.solve(eqs[0].subs({i:I}), u[k, I+1])[0]\n",
    "(eqs[2] * 2 * h_x * gamma).subs({u[k, I+1]: solution}).expand().collect([\n",
    "    u[k, I-1],\n",
    "    u[k, I],\n",
    "])\n",
    "# (eqs[2] * 2 * h_x * gamma_val).subs({u[k, I+1]: solution}).expand().collect([\n",
    "#     u[k, I-1],\n",
    "#     u[k, I],\n",
    "# ])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## КН повышенного порядка аппроксимации"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4612 characters]\n",
      "text/latex": [
       "$$\\left [ - \\gamma {u}_{k - 1,i + 1} - \\gamma {u}_{k - 1,i - 1} + 2 \\gamma {u}_{k - 1,i} - \\gamma {u}_{k,i + 1} - \\gamma {u}_{k,i - 1} + 2 \\gamma {u}_{k,i} - 2 {u}_{k - 1,i} + 2 {u}_{k,i}, \\quad - 2 H h_{x} {u}_{k,0} - {u}_{k,-1} + {u}_{k,1}, \\quad 2 H h_{x} {u}_{k,I} + {u}_{k,I + 1} - {u}_{k,I - 1}\\right ]$$"
      ],
      "text/plain": [
       "[-γ⋅u[k - 1, i + 1] - γ⋅u[k - 1, i - 1] + 2⋅γ⋅u[k - 1, i] - γ⋅u[k, i + 1] - γ⋅\n",
       "u[k, i - 1] + 2⋅γ⋅u[k, i] - 2⋅u[k - 1, i] + 2⋅u[k, i], -2⋅H⋅hₓ⋅u[k, 0] - u[k, \n",
       "-1] + u[k, 1], 2⋅H⋅hₓ⋅u[k, I] + u[k, I + 1] - u[k, I - 1]]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eqs = [\n",
    "    (u[k, i] - u[k - 1, i]) / h_t - D / 2 * (\n",
    "      (u[k-1, i + 1] - 2 * u[k-1, i] + u[k-1, i - 1]) +\n",
    "      (u[k, i + 1] - 2 * u[k, i] + u[k, i - 1])\n",
    "    ) / (h_x**2),\n",
    "    (u[k, 1] - u[k, -1]) / (2 * h_x) - H * u[k, 0],\n",
    "    (u[k, I+1] - u[k, I - 1]) / (2 * h_x) + H * u[k, I],\n",
    "]\n",
    "eqs[0] = (eqs[0] * 2 * h_t).expand().subs({gamma_val:gamma})\n",
    "eqs[1] = (eqs[1] * 2 * h_x).expand()\n",
    "eqs[2] = (eqs[2] * 2 * h_x).expand()\n",
    "eqs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $i=1,I-1$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtEAAAAZCAYAAAD37XL3AAAABHNCSVQICAgIfAhkiAAACCNJREFUeJztnW2oHcUZx38pYnJzA760iFjRVG21fvFajSQocq1aKfQF9YMf+qFbW6pgLCJiW+tLrMEUKlgtohSRa6lgixLbKNgKJa2xtDEV8TUV2x5FY2uxqRgSMdHbD88sd++ePffMzs6+nHP+P7ice2ZmZ595nv/OnpndnQUhhBBCCCGEEEIIIQK5H3gbmG7bkA5wGjAPfKttQyYI6W8B6U8IIYQYEdYAHwFX59I/jp3INwOvAvuAd4FtwDeBjzVoYyihbdgMvAWsasDGSUf660f6E0IIIUaA3wH/A6Zy6ZdjM2K7gAeATcB9ruw88BCwrDkzgwhtwxku/7pmzJxopL9+pD8hhBCiZhLsZDsbuP1nsFnAnxXkfR74Mv2zZUcCr7v9Xhy436ao0oaXgdcKthWLSQjX4KjoLyGsjWOpv5gGXQjsB/4CHDugzM2Yo77tvn/ffb+ooOwxLm9zRBtFNRTj8Ucxbg/5vl0uxWbCflmQ93tgC/YjJ8u/gHvc/7OZ9JBY1k3ZNmR5ENPT+bl06S8eMfUH3dNgHfqDljUY80f028AT2NT7tQX5x7n0p4F7Xdpp7nNHQfk17vOZiDaKaijG449i3B7yfbucB3wI/Lnkdvvd54FMWkgs26SoDVmecp/5HzHSXzxi6g9GS4Oh+oMx0+ByYA828snzKCaQ0zNp/wT+M6CuTdgI4ksxDRSVUYzHH8W4PeT7cBLCL6VPYyfw50tud5DbZh64IJdXNpZtsVQbUg5x+dtz6dLfYhLCNFiH/qAeDSZUu20qTxX9wRhqcDv2xGWWr2AN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dV2H0xz2GjspXYze9ZZjBn3Yc9XfqHJezYiDV4Kc4Btg4pU5ZTGHxf0HUsfnXlcizI12TSvgg8Gdmm2CjGg2Pclk2x6UqM8+j4WqArvh8XzT+MnVgvAF7N5X0d+CG2JNiT2ANReXr0P1jlG8smCG0DwBfcdr/OpE1i/14ndegPuqPB2PqD7vSB0dnC8KdiV2CXFnZh0+M7sOn3Q7F7X7YWbLMTWxR8L/Y2nqX4BDbVv9TfyiF1hIxiX8HeEV/E4ZiQ07+HgTtzaVM12FQHinG3bKqDLsQ4j46vBbri+xiah/Znog/GnuQvWlN3A8NXJtg6oF6fWDbBBsLacAh2+fuRXPok9u/DSAjXYF36g7gaTAhr4wbi6g+60wdGZxs2avDpOH1Z6epcA3wNOzg+F7H+IsoegNOYjWs9y88xmpebQTH2jXEIinExOr6q0aTvQ+iC79NXCJ8asc46YtkkV2I+OatiPerfh1OH/mC0NRhLf9D9PhCwm7/fw5Yticla7L6edCbpFmzdwE9G3s8qbLp/Bhup3Oj+P8Zj23WUE+ocfif5KjbVgWIcvzNSjIej46saTfrel675fgX2kNKWSPXVFcummMJm+R6KUNck9+++xNYfjLYGY+oPutkH9pG+eeeByPVeji3InbIM+BW2PmDMRs1SfJlhLlMmcWmrC2zciT9z+J3kfWxqEsU4Pj42NUmbMU7Q8TXqvvdllm75HuxlHTdhM09VqSuWTfFZ7BhaHaGuSe7fyxBTfzDaGoypP+hmH9jHJfQ/zDNu3Ay8SD0PZo4CivH402aM5Xv5flyYhL5yFJkknUuD5ZgkbbTG08R7b7zoJopxe8j37SHfi0lAOheDkDaEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBATw/8BrPeaZG9W7x4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$- \\gamma {u}_{k - 1,i + 1} - \\gamma {u}_{k - 1,i - 1} - \\gamma {u}_{k,i + 1} - \\gamma {u}_{k,i - 1} + \\left(2 \\gamma - 2\\right) {u}_{k - 1,i} + \\left(2 \\gamma + 2\\right) {u}_{k,i}$$"
      ],
      "text/plain": [
       "-γ⋅u[k - 1, i + 1] - γ⋅u[k - 1, i - 1] - γ⋅u[k, i + 1] - γ⋅u[k, i - 1] + (2⋅γ \n",
       "- 2)⋅u[k - 1, i] + (2⋅γ + 2)⋅u[k, i]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(eqs[0]).collect([\n",
    "    u[k, i-1],\n",
    "    u[k, i],\n",
    "    u[k, i+1],\n",
    "    u[k-1, i-1],\n",
    "    u[k-1, i],\n",
    "    u[k-1, i+1],\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $i=0$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlAAAAAZCAYAAAD+KhDIAAAABHNCSVQICAgIfAhkiAAACXtJREFUeJztnWusHkUZx38teOyNcAmJBoXWIhQaI6fUKgjiq0GDX7wgpkETswLxwiVBgwaNqRCImmiMhXj3QyWgYCAY+ACWD3gp1VIo9UarBDkY2wIKqFSwCtQPz2zOdpmdd3Zm9vKefX7JyZ53Znb2mct/dm67C4qiKIqiKIqiKIH8AHgCWNyxHZ8E9gMf7NiOIbEayfMLujZE6YUOVYPdoDpUlAlkDfAi8KkK/42IsEeOOL5twnw00pbrTTwnRMYzZM4BrgV+CfwLyc/rx5xzK7AHWNKsaYoDlw5Vg5OH6lBRBsBG4B/Awgr/J4HncY+KH0AaiJMjbXkQeAaYHxnPkNmOlMUzwA78Gu43mnCfa9Y0xYFLh6rByUN1qCg9J2P8yNTF8cio97sV/stN/L9xxLEI+B/wH+BlgXaA3BxeADZFxBFCRlwe9o23AccB85A0+TTcII38o+iNM4SM5nQ4BA1C/3SYEWfPnNZhSuPeh1TeLcDSijBXcuD06mfN77MtYY8xfrcmtHFIaHn4cx4i8Jsq/N9gjlsccawGDgZ+i+Q7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ai9gPRo5jrnSg+l4efcin/BMBq8YFDKSJMjgJGVmdh+zD+GnCuENpIp1tcQlSB06PjKeLtgrCN5GXvz33J8I2kadAdRjPJGsQ+qPDTrQxD+mlP5g43lOQHmH+le6rkOm7VyW+zhJk49k00mtdZ/4/pqXzU9PX8uhbPi1ANife3kDcTZTBUmQkts78fh0yChslvEZdmqprbbAQyc+bE8TVVlsF8TpaiyxbXQCciIzw91L9PbWmUR3GMckahH7psBNt5C89uyFxvB9HplBz5gE/Rp6ISNnTHmGfatxQCJMZt2WB57dJl+WRMTn5BLLe/QVkY2JKUpfBEUjel5cabsL9ssGmaaqutcGJyHLDsgRxtdVWwXgdZVRrMOdCZClln7HR9hmbNlEdhjPJGoT2dZjh1kfr2lhrDLqs6Qt1yJXAH0j7LcGm6LI8JimfmmQImoDhpHOSUA3OMoT6OYQ0pkT10QFb6XapZFLQfFKUblENKko1qg9FURRFURRFURRFURRFURRFURRFURRFURRFUQbL/wGv1jgdcREc6gAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$- \\gamma {u}_{k - 1,1} - \\gamma {u}_{k,1} + \\left(H \\gamma h_{x} + \\gamma - 1\\right) {u}_{k - 1,0} + \\left(H \\gamma h_{x} + \\gamma + 1\\right) {u}_{k,0}$$"
      ],
      "text/plain": [
       "-γ⋅u[k - 1, 1] - γ⋅u[k, 1] + (H⋅γ⋅hₓ + γ - 1)⋅u[k - 1, 0] + (H⋅γ⋅hₓ + γ + 1)⋅u\n",
       "[k, 0]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(eqs[0]/2).subs({i:0}).subs({\n",
    "    u[k, -1]: Ω.solve(eqs[1], u[k, -1])[0],\n",
    "    u[k-1, -1]: Ω.solve(eqs[1], u[k, -1])[0].subs({k:k-1}),\n",
    "}).expand().collect([\n",
    "    u[k - 1, 0],\n",
    "    u[k - 1, 1],\n",
    "    u[k, 0],\n",
    "    u[k, 1],\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $i=I$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAnIAAAAZCAYAAAC1gsMlAAAABHNCSVQICAgIfAhkiAAACLpJREFUeJztnXuoHcUZwH9JNeYmER8UFLUmJtVoKHpjTFUUPYoW/aetaUC0INta6husqGgpPlB8oIgP8IV/pKJWS0Kk+aM2QXzUd2xM6yMRUa9iTH1Ejc+q0fSPb5a7Z++c3Tk7s49z9vvBZe+Zx7ffzLffzO7M7CwoiqIoiqIoiqIolfFn4H1geo06/AHYCpxcow5tYwFS57+rW5EWoj7XTtTnFEUJzkLge+A8S9xKpNHpZOS/3aT5vace9xg5+3rKaTuLgVuAfwKfInV6T0b65cBGYEb5qikG9bnhQn1OUZRaWQl8AoxY4jYBW8geNXgBabgO9NTjFeAzYLKnnLazFrHHZ8A68juVn5o0fyxfNcWgPjdcqM8pilKYiPyn9yz2QUYG7rTEzTay/52RfxrwLfA/YNuCOoB0Wt8BT3jIKEqEXx02jaOAvYFJSJnyOhWQzucttEN3IUJ9zpeIZvlchJ8+Q+VzIRU6AblYnwVm9khzOd3Dyxeb34ssafc0ccsD6qj4oTaun98ijc8DlriDzPHZjPwLgG2A/yC2hGJ2HUXajzXAPKQR/C/wOfAUcHB+USqnSDmr4BHgNXNeV+5H/OdYS5z6XFjU54qjPleBz4W8kXsfWIUMQV5oiZ9twlcDd5mwBeb4vCX9QnNcE1BHxQ+1cf0cgzyVP2OJc+lUDjHHpD2K2DWeIpppZO0A3A08BhwK/A3YPkOPOihSzqbypDnaOhX1ubCozxVHfa4Cn9smoKwnkbvvTYxf3EluBqYAZyLD1CCF/xB425I+lvFCQB0VP9TG9TIdeSpfB3xhiY/r80Rk6sBG/NSebHCK2hWkkzqc7kZqGfJkOoosJm4KRcrZVFab4xGWOPW5cKjP+aE+N6A+9xywORX2c2Ro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 1,I - 1} - \\gamma {u}_{k,I - 1} + \\left(H \\gamma h_{x} + \\gamma - 1\\right) {u}_{k - 1,I} + \\left(H \\gamma h_{x} + \\gamma + 1\\right) {u}_{k,I}$$"
      ],
      "text/plain": [
       "-γ⋅u[k - 1, I - 1] - γ⋅u[k, I - 1] + (H⋅γ⋅hₓ + γ - 1)⋅u[k - 1, I] + (H⋅γ⋅hₓ + \n",
       "γ + 1)⋅u[k, I]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(eqs[0]/2).subs({i:I}).subs({\n",
    "    u[k, I+1]: Ω.solve(eqs[2], u[k, I+1])[0],\n",
    "    u[k-1, I+1]: Ω.solve(eqs[2], u[k, I+1])[0].subs({k:k-1}),\n",
    "}).expand().collect([\n",
    "    u[k - 1, I],\n",
    "    u[k - 1, I+1],\n",
    "    u[k, I],\n",
    "    u[k, I+1],\n",
    "])"
   ]
  }
 ],
 "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.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
