{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "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": 3,
   "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": 4,
   "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')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "u = Ω.IndexedBase('u', shape=(I + 1, K + 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "gamma = Ω.symbols('gamma')\n",
    "gamma_val = D * h_t / h_x**2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "## простейшая явная"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4608 characters]\n",
      "text/latex": [
       "$$\\left [ - \\gamma {u}_{k - 1,i + 1} - \\gamma {u}_{k - 1,i - 1} + 2 \\gamma {u}_{k - 1,i} - {u}_{k - 1,i} + {u}_{k,i}, \\quad - H {u}_{k,0} + \\frac{- {u}_{k,0} + {u}_{k,1}}{h_{x}}, \\quad H {u}_{k,I} + \\frac{- {u}_{k,I - 1} + {u}_{k,I}}{h_{x}}\\right ]$$"
      ],
      "text/plain": [
       "⎡                                                                             \n",
       "⎢-γ⋅u[k - 1, i + 1] - γ⋅u[k - 1, i - 1] + 2⋅γ⋅u[k - 1, i] - u[k - 1, i] + u[k,\n",
       "⎣                                                                             \n",
       "\n",
       "                  -u[k, 0] + u[k, 1]              -u[k, I - 1] + u[k, I]⎤\n",
       " i], -H⋅u[k, 0] + ──────────────────, H⋅u[k, I] + ──────────────────────⎥\n",
       "                          hₓ                                hₓ          ⎦"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eqs = [\n",
    "    (u[k, i] - u[k - 1, i]) / h_t - D * (u[k - 1, i + 1] - 2 * u[k - 1, i] + u[k - 1, i - 1]) / (h_x**2),\n",
    "    (u[k, 1] - u[k, 0]) / h_x - H * u[k, 0],\n",
    "    (u[k, I] - u[k, I - 1]) / 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": {
    "hidden": true
   },
   "source": [
    "### $i=1,I-1$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAAZCAYAAADNJ3IwAAAABHNCSVQICAgIfAhkiAAABsVJREFUeJztnWuoVFUUgD/N0usVfCQhJWWWj0Ty9lCUSq5l9aOXWdGPgoaKErKQiB5SdBVJocAselARt0ioSKyMsIIUtah8JGn5SO0qpWWRWaKl1u3H2oNzj3tm9jlnn8fMrA+Gc2c/18za66z9WGcuKIqiKIqiKA3Na8BeoDlrQeqEC4BO4M6sBVEURf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      "text/latex": [
       "$$\\gamma {u}_{k - 1,i + 1} + \\gamma {u}_{k - 1,i - 1} + \\left(- 2 \\gamma + 1\\right) {u}_{k - 1,i}$$"
      ],
      "text/plain": [
       "γ⋅u[k - 1, i + 1] + γ⋅u[k - 1, i - 1] + (-2⋅γ + 1)⋅u[k - 1, i]"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ω.solve(eqs[0], u[k, i])[0].expand().subs({gamma_val:gamma}).collect([\n",
    "    u[k-1, i-1],\n",
    "    u[k-1, i],\n",
    "    u[k-1, i+1],\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "hidden": true
   },
   "source": [
    "### $i=0$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADYAAAAjCAYAAADfXvn1AAAABHNCSVQICAgIfAhkiAAAAuBJREFUWIXt2E+IV1UUwPHPmATKkFILBWVENFES/c0fkRaJgTuJ2thGCEFoYYtoIZS4KF0YLvy3F1xFyVSkaEEJQlgbJzVCzP5AVCBI6aAWaKSLc19zf2/e2G98v9/MLH5feLx7zzv33nPeufe9ey5dKtmEu3g8ky3GfaycFosSs2q278dl4Vwu+wtXa/Zdi7qONXCxJOvHd/gXL+JQi319jBsYrmkT2hOxSyVZ7uyaiucTcRiv1LTnP+o4NgcrjI/YOmPOFI49gU/w6kP6O4tbNexpYnaNtsvwGH7IZBvEx6NwdhX+xqd4G5/XGG/KWCjW0UupPoTvk6xXRPQGLuCZFvvcaAassWvYhaP4FW/gffyE21iNr9MY/9Qzc2axHW9hACMiigVnsKiizUZtilgnOYwXUnk7jqdyD34RUzXnC1wX/8Df8OwU2NhWVuHAdBvRpUuXevSk+/1ptaJL53lX/HdmLOUt1Rm8V6H3stgDzkv1qjxsqtiAE/hdLKFtVUplxwZwvkJvCD9iNNUbWs+zWuWYyAD+j16RyL4uModKcseWYb6JHRtJ5YVYII4DTuOO2Pg+34JR7eC02HwPi1lUSe7YYFL8pqTTY2wjS0QLXsNBrBVvcEZtk/JEc1A4OlEWmzs2KtbdtSQbxr5OGPio5BEbwClxjpFfu8UiLSLZwEljTsFysQYnwy6RtxXX1grZc5Pss5I/sLNCvl/zUdoV7CjpnNB8GnUO61P5qEhCyzwpXkhxfYgjJVk5tSlz2wRfxWIqLk0DjVTo5OtrLp4W6X5OPz7K6nvxJr4U6/ZgRb9/pqvgVqpPNvKVFFNxMN3LHw7C6MKxNen+bfb8Kc0HOPAZ+rDZ+OjWpVcsh4awvy+V+3Kl3LGfcbPUyRLNkWyIU6k7mU4/7okT4YJ1qd1oetZOhsSMuSCm6jupvKfN44xjkfh5LxUzYHWnB5wK5uArse2BLfhg+szp0qVLp3gArXKVkSmRbzYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{{u}_{k,1}}{H h_{x} + 1}$$"
      ],
      "text/plain": [
       "u[k, 1] \n",
       "────────\n",
       "H⋅hₓ + 1"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ω.solve(eqs[1], u[k, 0])[0].expand().subs({gamma_val:gamma})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "hidden": true
   },
   "source": [
    "### $i=I$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADYAAAAjCAYAAADfXvn1AAAABHNCSVQICAgIfAhkiAAAAxZJREFUWIXt2FuIVlUUwPHfRAgTQ0U+FBgTQyUKYt9cJAoSg+olIhDyoUIEoYd8kAKhhoguUNFDZj2G0JNUTEVG0kNCFNZLkyYW4Q0EK6HroBVUND2sffj2nDnfbb75ZoS+PxzOPmuvvfdaZ6995X/KHfgLKzLZtZjFmmWxqE0uaZE/im+Ec7nsDxzvlVGLQSvHajhSko3iGP7FvXi5zbYexXMdWVfnXfyKqXYLtNNjX5VkubPrK/IbsU78kIWwB1s7KdDMsUGsNr/HNqg7Uzh2Od7DQ03q68axj3F+gWUrDZkVk0XBxiS7NX0fw1ocwp1N6hoQobSiiU4rNukgFC9tkveTcGICZ9P7tSQ7Knp0FfbhQXzdpK4R/GDuJEREQ5UNd+H71uY3pplj5zCJvXgVn+AN3I8LIiQ/F87906KdRmFY69DeJWE7HscYpjGU5R0UDhdM4sku29ukg1Dshj24J6W3462UHsAZEaoF+7C5i7Y+wo9i/TyLW7qoa8GsxUvL0XCfPn2WjoH0nl1WK/r0nhfE2nLRUt7dHxSLaZkt4vx1RfquOqctFRuxH9+JIbStSqns2Bi+qNCbwEnMpO+a9s9h7fI6nmpDb0jsO3fiz0ZKuWPX40qNHZtO6WtwtdipH8DvOIXb2zBqMTgg9p5TIooqyR0bT4pflnQG1De61HfkO7AbN4k/eFFto/Jjy7hwtNFJNXdsRoy7c0k2hed7YeBCyXtsDB+Ie478eUIM0qIna3hf3Sm4QYzBTpgU57rieaBCdluHdVbyM3ZVyF8096rtWzxc0tlv7m3VIdyc0nvxSEW9V4kfUjxv45WSbLCiXM4FDWbFIhRHUkPTFTr5+LoMN+JwSWcU72Tfz+IxfCrG7e6Ken9JT8H59N1pz1dShOJ4epcnDsLowrH16X00y18pLnzyde1DDONu83u3W4bEcKgJ+4dTejhXyh07jd9KlVxnbk/WcEJM8QWj+FvcGBdsSOVmUt5iMiEi5rAI1adT+plFbmceq8TiPSIiYF2vG1wKBvGZ2PbAfXhz+czp06dPr/gPRuyh+uS9hDQAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{{u}_{k,I - 1}}{H h_{x} + 1}$$"
      ],
      "text/plain": [
       "u[k, I - 1]\n",
       "───────────\n",
       "  H⋅hₓ + 1 "
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ω.solve(eqs[2], u[k, I])[0].expand().subs({gamma_val:gamma})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "## простейшая неявная"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4652 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,0} + {u}_{k,1}}{h_{x}}, \\quad H {u}_{k,I} + \\frac{- {u}_{k,I - 1} + {u}_{k,I}}{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, 0] + u[k, 1]              -u[k, I - 1] + u[k, I]⎤\n",
       " 0] + ──────────────────, H⋅u[k, I] + ──────────────────────⎥\n",
       "              hₓ                                hₓ          ⎦"
      ]
     },
     "execution_count": 126,
     "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, 0]) / h_x - H * u[k, 0],\n",
    "    (u[k, I] - u[k, I - 1]) / 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": {
    "hidden": true
   },
   "source": [
    "### $i=1,I-1$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iV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E6NhiVqGUMS9C2Y61lD+TXBjeHypaZ8cgmiTcifxw55zrYIu4EgjWkduw6gRZkCteK9N6PqHv9xZi0SEJ3SFd7W/KmfR9kA3BZjGkmVZ9p0ISMgBfHkFYU+4PkbDBOopYxCFHajrWWI5ARwMLQ2axmOvJyjUcP4E1ks83LUFF971BD3K3Y045dJ1Ag+os3cZKE7pCu9rYUyJf2IC/hPEp8/1QmqfpMg7OQNjQ0hrSi2J8XPwkbjBObMsZFAf+2UyRie76O6o3VNJgDfIV5s7oRyEp3cNonQZb12dVw9hcvXVbPdbjf/c4Kp70jS5z9xYvT0+FwOBwOh8PhcDgcDofD4XA4HA5HFf8B2Sn0Vmz2OcMAAAAASUVORK5CYII=\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": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-eqs[0].collect([\n",
    "    u[k, i-1],\n",
    "    u[k, i],\n",
    "    u[k, i+1],\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "hidden": true
   },
   "source": [
    "### $i=0$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAL0AAAAZCAYAAABkWi/IAAAABHNCSVQICAgIfAhkiAAABdxJREFUeJztm11sFUUUx39FrP0iKJJoJKGEWCmEhFsqWgSb+m1iVFQM8SPmBoko0QeNJmpM1WjUJ2M1JioG0fAAxgbUB6QvVUSlKl+KFkWwmEgF8QNBEBTw4T+bu507d+/edru9l+4vuZnuzJzZObszZ86c2UJCQgIAbwJ7geoI27wfOAHcG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ufowPCWWSvXH7K0bO3V9gO4KJ8CkRMnHrnxT/oTwBrkR96rlWnAThKX1/dJpffNh1Z7a0OGW9C2Ap7J5pp4GGgFbgGWalSwAvd2ivYUXRoV+fLqwaWAFPNtR3BSCEDMAedaSwGbifbdbIZiwITtpHYg6xonMSpd15GWtftwE3AVcAPJq8e+UibTOdd1CCFDgLbfPnlSKkt9D2s8ghaBTpQ6O9p4FoyYcA4mWN+kBkoM8lsgPehVcjmSrSvedfKX4Ni0mvRQUwNcBk6zOtFJ9o7LZkUerZLgOvQ2UapUdR6lyNL4D+AugNZ3tcD5GaRWSn8eF8dvppDrht911LmKLsUnRccI/s7nkJI03+f/gmCoxY9DpnRyBqtcpRVoL3JbuAQWhUXos33ceBDh8w29OwPATcU0Pdy5A7cbOW/TPwTJ069bbJ8ehfecXFDvoqDyDQU0ZmPVp9c8d1i5D70/GZH0FYVmvQzgNvQCyzEAHSR/R3V98S/kS2UgertJ9Sgr0Abjvf7eZOBUossQqu5noqsQcsQ9acQKlHf34movSZkrb0vXp9CsedxIeXnIZd0AToraUODwBVFKSYGqncNco9SaKVoNX/bh4V9aAYeJ9p/IgnDGOTy2O7QCuCzmPvSHyYjl2hCRO3dTebEGuQGvo32QFUmL41Wllz3XITcsCNGzvVpRLExUL1bcLujSwehrwlDwJMoqmYHJU52hqveCSiq1TLUnRgChqveCQkJCQkJCQkJCcOe/wHOT5SuMUTYXgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left(H h_{x} + 1\\right) {u}_{k,0} - {u}_{k,1}$$"
      ],
      "text/plain": [
       "(H⋅hₓ + 1)⋅u[k, 0] - u[k, 1]"
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(-eqs[1] * h_x).expand().collect([\n",
    "    u[k, 0],\n",
    "    u[k, 1],\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "hidden": true
   },
   "source": [
    "### $i=I$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "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\n",
      "text/latex": [
       "$$\\left(H h_{x} + 1\\right) {u}_{k,I} - {u}_{k,I - 1}$$"
      ],
      "text/plain": [
       "(H⋅hₓ + 1)⋅u[k, I] - u[k, I - 1]"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(eqs[2] * h_x).expand().collect([\n",
    "    u[k, I-1],\n",
    "    u[k, I],\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "## КН"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 5156 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 - H {u}_{k,0} + \\frac{- {u}_{k,0} + {u}_{k,1}}{h_{x}}, \\quad H {u}_{k,I} + \\frac{- {u}_{k,I - 1} + {u}_{k,I}}{h_{x}}\\right ]$$"
      ],
      "text/plain": [
       "⎡                                                                             \n",
       "⎢-γ⋅u[k - 1, i + 1] - γ⋅u[k - 1, i - 1] + 2⋅γ⋅u[k - 1, i] - γ⋅u[k, i + 1] - γ⋅\n",
       "⎣                                                                             \n",
       "\n",
       "                                                                    -u[k, 0] +\n",
       "u[k, i - 1] + 2⋅γ⋅u[k, i] - 2⋅u[k - 1, i] + 2⋅u[k, i], -H⋅u[k, 0] + ──────────\n",
       "                                                                            hₓ\n",
       "\n",
       " u[k, 1]              -u[k, I - 1] + u[k, I]⎤\n",
       "────────, H⋅u[k, I] + ──────────────────────⎥\n",
       "                                hₓ          ⎦"
      ]
     },
     "execution_count": 8,
     "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, 0]) / h_x - H * u[k, 0],\n",
    "    (u[k, I] - u[k, I - 1]) / h_x + H * u[k, I],\n",
    "]\n",
    "eqs[0] = (eqs[0] * 2 * h_t).expand().subs({gamma_val:gamma})\n",
    "eqs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "hidden": true
   },
   "source": [
    "### $i=1,I-1$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAuEAAAAZCAYAAACfHvDPAAAABHNCSVQICAgIfAhkiAAACGxJREFUeJztnXuoZVUdxz8j2sydO+ATERMdzVcieCtHRoq4miZRminRHwltMnIgC4kofKRjSQYFaSCJhlxFQUUZcxJ8gE0zo5SvRFMnsbpGjmaiiTITvqY/fut0z913n7PX3nvtvdc++/uByzln7fX4rd/vu8/97dc6IIQQQgghhBBCCCFECW4EXgWm2zZkQvgEsAv4RtuGRIC0FRZpSwghhJgQ1gAfAN+toe99sWRhA/ACsBN4E9gKnAvsVsOYoSk7hw3Ay8CqBmyMFWlrPNKWEEII0WPuB/4DTNXQ9zrsrN124BbgSuAGN94u4A5gWQ3jhqTsHE5w2y9qxswokbbGI22J3pBgop1t1wxRIwmKcVskyPdtkVDe90diZyqvC2jPMCcDp7P0jN4BwD8wu8+uaexQVJnDc8CLGW27QoK0lUdCeR/1WVuVGJ70l4B3gT8Ch4yofznmzG8CF7r3Z2XUO9ht2xDMUlGVovEFxbhrKMbtId+3y9exM2231dT/g8BGLBkb5hXgWvd+dqi8jB7qpugchrkV0+SpqfI+aDg2bUF8+qpDW9ADfQ0n4a8CD2CXB76fUfcwV/4o8GvspnqAxzLqrnGvT4QxUwSgaHxBMe4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Hp8QTFuM8byvXwvFujD921IpOFiSF/xIQ3n8CjVF6MXcaMYt4d83x7yveg60rDoOtKwEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBC9IT/ATdDtjEGsW6yAAAAAElFTkSuQmCC\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,i} + \\left(- 2 \\gamma + 2\\right) {u}_{k - 1,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, i] + (-2⋅γ + 2)⋅u[k - 1, i]"
      ]
     },
     "execution_count": 123,
     "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": {
    "hidden": true
   },
   "source": [
    "### $i=0$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAL0AAAAZCAYAAABkWi/IAAAABHNCSVQICAgIfAhkiAAABdxJREFUeJztm11sFUUUx39FrP0iKJJoJKGEWCmEhFsqWgSb+m1iVFQM8SPmBoko0QeNJmpM1WjUJ2M1JioG0fAAxgbUB6QvVUSlKl+KFkWwmEgF8QNBEBTw4T+bu507d+/edru9l+4vuZnuzJzZObszZ86c2UJCQgIAbwJ7geoI27wfOAHcGmGbxUYj0nHBUHckoTBmAMeBBxxlHeiltgTIv2Lq3GXlLzP59QPvYmzMBV4CPgb+Qv1flkdmJ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C2Ap7J5pp4GGgFbgGWalSwAvd2ivYUXRoV+fLqwaWAFPNtR3BSCEDMAedaSwGbifbdbIZiwITtpHYg6xonMSpd15GWtftwE3AVcAPJq8e+UibTOdd1CCFDgLbfPnlSKkt9D2s8ghaBTpQ6O9p4FoyYcA4mWN+kBkoM8lsgPehVcjmSrSvedfKX4Ni0mvRQUwNcBk6zOtFJ9o7LZkUerZLgOvQ2UapUdR6lyNL4D+AugNZ3tcD5GaRWSn8eF8dvppDrht911LmKLsUnRccI/s7nkJI03+f/gmCoxY9DpnRyBqtcpRVoL3JbuAQWhUXos33ceBDh8w29OwPATcU0Pdy5A7cbOW/TPwTJ069bbJ8ehfecXFDvoqDyDQU0ZmPVp9c8d1i5D70/GZH0FYVmvQzgNvQCyzEAHSR/R3V98S/kS2UgertJ9Sgr0Abjvf7eZOBUossQqu5noqsQcsQ9acQKlHf34movSZkrb0vXp9CsedxIeXnIZd0AToraUODwBVFKSYGqncNco9SaKVoNX/bh4V9aAYeJ9p/IgnDGOTy2O7QCuCzmPvSHyYjl2hCRO3dTebEGuQGvo32QFUmL41Wllz3XITcsCNGzvVpRLExUL1bcLujSwehrwlDwJMoqmYHJU52hqveCSiq1TLUnRgChqveCQkJCQkJCQkJCcOe/wHOT5SuMUTYXgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left(H h_{x} + 1\\right) {u}_{k,0} - {u}_{k,1}$$"
      ],
      "text/plain": [
       "(H⋅hₓ + 1)⋅u[k, 0] - u[k, 1]"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(-eqs[1] * h_x).expand().collect([\n",
    "    u[k, 0],\n",
    "    u[k, 1],\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "hidden": true
   },
   "source": [
    "### $i=I$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw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myqwPa32bqPGrlX0/+2/TJKPy9zsrvAv5FwQSPR9CPfEKADC6yFB+O9tNJ+HD0BKSXbUV7TR8NOS3gRlN2n5V/oslvNt/rTD8bkUsUxKnEo3sUxpqOe3FYHL+rtgP4DZjlaBzG4rSYNF9gwLUDtSA3zy5bDXwN3GW+3wosAS4Afg2QISnMQnrZFm02CtNvs/KPAZaZv+0xziDL9b3p9zN0Cb2AXAtq470CVM4I1njQccTCGQLeR375aVadFuAAI88uNvl821ZkPbY42niLylbau3nPArcD3cBF6E6lEvDC8rYlPYAuhpt8eXXAs8Bc892ONmXQJrIY3Xk9DVxJrhvoog1Zvd1hBY+B8aBjDkvQpL3Bl9dM4RVdj8419is1E9FAbnA1Yvj9NZeVAw3iQeDCQoIHkKV4U74YBRB6kF8+hH4kL+/BPO1eQnKfbOUvN33sAB5H/vN2FDQZQK86VVltelGgYRA4J6L8b5v25SRJOq6gcLCjs0D/TlfNZiJyhfyXnFeZBzwT0G4BwxbLj2dGn8zTrg8tNnsgARah+6RD5L73FoUsxS+cewge9H5Hmylop3zVUVaDzmoDwD5knZehgMZh4F1Hm+/Q2O8DLoko/y509iwnSdJxGnIdgz61BfoPtXBg+HWJlkIVS8g8tPssReedfHcCSeQmNH4LY+irFm0c84Er0I8YdhM5xcixKAY5SknSdQy9cGrQwe71EgoTRAParbrN97lop+ocJXmiMAnJ/kpM/bUjl897U305cnumh2jbhSaVHZ5PGknUsR6duzLICnabv+0L7Rw6gLuJ9x/ZwjAVuW+2a7cK+KTMshTDHOTezYypv+sYfrMC5NK+jKKQnouRRZPHfub9xHOpXGqSqGMnbte8pwTPShkl7kXRzupCFSuY8aBjSpnZQGW4sUfCeNAxJSUlJSUlJSUlJSVl1PgfCDirCadaf2EAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(H h_{x} + 1\\right) {u}_{k,I} - {u}_{k,I - 1}$$"
      ],
      "text/plain": [
       "(H⋅hₓ + 1)⋅u[k, I] - u[k, I - 1]"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(eqs[2] * h_x).expand().collect([\n",
    "    u[k, I-1],\n",
    "    u[k, I],\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## простейшая неявная повышенного порядка аппроксимации"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 6488 characters]\n",
      "text/latex": [
       "$$\\left [ - \\frac{D \\left({u}_{k,i + 1} + {u}_{k,i - 1} - 2 {u}_{k,i}\\right)}{h_{x}^{2}} + \\frac{- {u}_{k - 1,i} + {u}_{k,i}}{h_{t}}, \\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": [
       "⎡  D⋅(u[k, i + 1] + u[k, i - 1] - 2⋅u[k, i])   -u[k - 1, i] + u[k, i]         \n",
       "⎢- ───────────────────────────────────────── + ──────────────────────, -H⋅u[k,\n",
       "⎢                       2                                hₜ                   \n",
       "⎣                     hₓ                                                      \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ₓ          ⎥\n",
       "                                                                ⎦"
      ]
     },
     "execution_count": 9,
     "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": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAAqCAYAAACjkKBgAAAABHNCSVQICAgIfAhkiAAACgNJREFUeJztnXuwVVUdxz9X4novD1F0JgQC0QQx0HuhS5B6uxJO1OikpjVmNqexzMb8Q+sPdSaD0TFm7CE12NO6kiVFRGAFPUytyJKnRqAUiRYPs0SKtNSwP75rz9l33/06j733Off8PjN7zj2/vfZav7Xu2Wv/1m/91tpgGIZhtDTHAc8ApxStiDFkWQl8rGglDKOZuR941R2voE77h8CCQLrbgW/kq5qRMzcCG4F/As8C9wEzcix/JvAcMCbHMg1jSHEQuBkYB5wE9ALLUQf/XpdmhEt3dgH6ZUU/sKhgHRqNnwAfQJ34TGA1cAAYm6MOm4BrcizPMIYMp6COuy/k3BrgKff3JchyagukWQC8BLT7ZBNdnqfVU9EM6Cd9h97M9ayFUcD/gAt8sqzb4mbg13XIxzBagqN8f89GN+KWkHTrgUnIOjsH2OzS+ukGdqAb3C97AdhVJ30bgVapZ5DR6Pdy0CfLui0eAeYAnXXIyzCGPMEOfTfymQbxbtiXgcnAvpA0XcC2gKwb2A4ccd/fCdyRQq/5VD8hthp1Ot+r8vokWqWeQZaiej/sk2XdFvuA4cD4SpU1jFbE36HPQpZ3GNPQzfUvZC39JyRNN/BoQBa84c8ISRPGL4DPRJwruSOKpcD7E/K/CTjsOy4PkZ0TcW1e9UwiTT0BbqU80R119CXk8Vk0Z/Iu5HbxyLotXnSfZqEbRgrSdOjDgUuBVe7731HYop9OYCqDrbUeBt7M3s19DPLLXxWh11o0EVcND6IHTxxfQh2Pd6wNkW0Kua7Z6gmyjqcnHI/EXP854DJkQf/ZJ8+jLbwJ2Gdj9MuDu4G/ASML1sNoXDyX9Qdry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xTcrKTQvR8vM761Js0bVkivH7e9cE6Tkc7kYalrzeXo/2bjgBfzKG8lmEh5WiI81A0xBrKs+ltaJJkURHKGUaGLEajzqG6OHGo188I4QY0ez7OJ7uC8lt2zkZP0W2+o9pXzhlGI7GR5t63PImhXj8jhBXANwOyxQyeUTcMw8icml911OJ0obc3+emmvhMghmEYqbAOvXpGoFVpWwNy69ANwzCajLkodMkf+XA8miT1VoduoPzqqLuA63LTzjAMw0hNWOjSArSMt919X4g247ke7RVhGIZhNDGb0UuRhxetiGEYQxvzoWdLD1oleght7WkYhmE0IRPQZlxT0NaXM+KTG4ZhGI1IJ9pjudd9v5T4d1MahmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYcfwfPEkFnxCCClgAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{D \\left({u}_{k,i + 1} + {u}_{k,i - 1} - 2 {u}_{k,i}\\right)}{h_{x}^{2}} - \\frac{- {u}_{k - 1,i} + {u}_{k,i}}{h_{t}}$$"
      ],
      "text/plain": [
       "D⋅(u[k, i + 1] + u[k, i - 1] - 2⋅u[k, i])   -u[k - 1, i] + u[k, i]\n",
       "───────────────────────────────────────── - ──────────────────────\n",
       "                     2                                hₜ          \n",
       "                   hₓ                                             "
      ]
     },
     "execution_count": 10,
     "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": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4844 characters]\n",
      "text/latex": [
       "$$- \\frac{2 D h_{t} {u}_{k,1}}{h_{x}^{2}} + \\left(\\frac{2 D H h_{t}}{h_{x}} + \\frac{2 D h_{t}}{h_{x}^{2}} + 1\\right) {u}_{k,0} - {u}_{k - 1,0}$$"
      ],
      "text/plain": [
       "  2⋅D⋅hₜ⋅u[k, 1]   ⎛2⋅D⋅H⋅hₜ   2⋅D⋅hₜ    ⎞                      \n",
       "- ────────────── + ⎜──────── + ────── + 1⎟⋅u[k, 0] - u[k - 1, 0]\n",
       "         2         ⎜   hₓ         2      ⎟                      \n",
       "       hₓ          ⎝            hₓ       ⎠                      "
      ]
     },
     "execution_count": 15,
     "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": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4880 characters]\n",
      "text/latex": [
       "$$- \\frac{2 D h_{t} {u}_{k,I - 1}}{h_{x}^{2}} + \\left(\\frac{2 D H h_{t}}{h_{x}} + \\frac{2 D h_{t}}{h_{x}^{2}} + 1\\right) {u}_{k,I} - {u}_{k - 1,I}$$"
      ],
      "text/plain": [
       "  2⋅D⋅hₜ⋅u[k, I - 1]   ⎛2⋅D⋅H⋅hₜ   2⋅D⋅hₜ    ⎞                      \n",
       "- ────────────────── + ⎜──────── + ────── + 1⎟⋅u[k, I] - u[k - 1, I]\n",
       "           2           ⎜   hₓ         2      ⎟                      \n",
       "         hₓ            ⎝            hₓ       ⎠                      "
      ]
     },
     "execution_count": 17,
     "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": 134,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 5360 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 - 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 - 1, i + 1] - γ⋅u[k - 1, i - 1] + 2⋅γ⋅u[k - 1, i] - γ⋅u[k, i + 1] - γ⋅\n",
       "⎣                                                                             \n",
       "\n",
       "                                                                    -u[k, -1] \n",
       "u[k, i - 1] + 2⋅γ⋅u[k, i] - 2⋅u[k - 1, i] + 2⋅u[k, i], -H⋅u[k, 0] + ──────────\n",
       "                                                                            2⋅\n",
       "\n",
       "+ u[k, 1]              u[k, I + 1] - u[k, I - 1]⎤\n",
       "─────────, H⋅u[k, I] + ─────────────────────────⎥\n",
       "hₓ                                2⋅hₓ          ⎦"
      ]
     },
     "execution_count": 134,
     "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"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $i=1,I-1$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAuEAAAAZCAYAAACfHvDPAAAABHNCSVQICAgIfAhkiAAACGxJREFUeJztnXuoZVUdxz8j2sydO+ATERMdzVcieCtHRoq4miZRminRHwltMnIgC4kofKRjSQYFaSCJhlxFQUUZcxJ8gE0zo5SvRFMnsbpGjmaiiTITvqY/fut0z913n7PX3nvtvdc++/uByzln7fX4rd/vu8/97dc6IIQQQgghhBBCCCFECW4EXgWm2zZkQvgEsAv4RtuGRIC0FRZpSwghhJgQ1gAfAN+toe99sWRhA/ACsBN4E9gKnAvsVsOYoSk7hw3Ay8CqBmyMFWlrPNKWEEII0WPuB/4DTNXQ9zrsrN124BbgSuAGN94u4A5gWQ3jhqTsHE5w2y9qxswokbbGI22J3pBgop1t1wxRIwmKcVskyPdtkVDe90diZyqvC2jPMCcDp7P0jN4BwD8wu8+uaexQVJnDc8CLGW27QoK0lUdCeR/1WVuVGJ70l4B3gT8Ch4yofznmzG8CF7r3Z2XUO9ht2xDMUlGVovEFxbhrKMbtId+3y9exM2231dT/g8BGLBkb5hXgWvd+dqi8jB7qpugchrkV0+SpqfI+aDg2bUF8+qpDW9ADfQ0n4a8CD2CXB76fUfcwV/4o8Gvspnq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66Ov8LSB6ImicuBZ8h+KLUPTHp8QTFuM8byvXwvFujD921IpOFiSF/xIQ3n8CjVF6MXcaMYt4d83x7yveg60rDoOtKwEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBC9IT/ATdDtjEGsW6yAAAAAElFTkSuQmCC\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,i} + \\left(- 2 \\gamma + 2\\right) {u}_{k - 1,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, i] + (-2⋅γ + 2)⋅u[k - 1, i]"
      ]
     },
     "execution_count": 135,
     "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": 150,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlAAAAAZCAYAAAD+KhDIAAAABHNCSVQICAgIfAhkiAAACXtJREFUeJztnWusHkUZx38teOyNcAmJBoXWIhQaI6fUKgjiq0GDX7wgpkETswLxwiVBgwaNqRCImmiMhXj3QyWgYCAY+ACWD3gp1VIo9UarBDkY2wIKqFSwCtQPz2zOdpmdd3Zm9vKefX7JyZ53Znb2mct/dm67C4qiKIqiKIqiKIH8AHgCWNyxHZ8E9gMf7NiOIbEayfMLujZE6YUOVYPdoDpUlAlkDfAi8KkK/42IsEeOOL5twnw00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YDc7asV5/0IycujS+519dF2WwWT34Gy6TClBsFdP2M0CP3RYUoNxtqTUodt3qM67UDdbi6eOcIsQKYYdyNPTtyHTMMdhqx9/sxyzk7kJWDPIu+8cHEkMuXn+ls0Jo650oHqQ3m46LoDNYU0NuWX9H3YxOt68dxpJswvxlxjXBnkXyH/ToX/DuQGUW4g3o68N+cF4r7/lZGmA+VT19rgCtwdkhnLOYci0/0/sfjV1UfbbRXU11E+W/GBkvs3kJdG1iUjvQ5TahDc9TNUg9AvHabUYEacPVeQTodt3qNSa6MWm5CK5CN6XxaZONcAH0Iai9gPRo5jrnSg+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": 150,
     "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": 151,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAnIAAAAZCAYAAAC1gsMlAAAABHNCSVQICAgIfAhkiAAACLpJREFUeJztnXuoHcUZwH9JNeYmER8UFLUmJtVoKHpjTFUUPYoW/aetaUC0INta6husqGgpPlB8oIgP8IV/pKJWS0Kk+aM2QXzUd2xM6yMRUa9iTH1Ejc+q0fSPb5a7Z++c3Tk7s49z9vvBZe+Zx7ffzLffzO7M7CwoiqIoiqIoiqIolfFn4H1geo06/AHYCpxcow5tYwFS57+rW5EWoj7XTtTnFEUJzkLge+A8S9xKpNHpZOS/3aT5vace9xg5+3rKaTuLgVuAfwKfInV6T0b65cBGYEb5qikG9bnhQn1OUZRaWQl8AoxY4jYBW8geNXgBabgO9NTjFeAzYLKnnLazFrHHZ8A68juVn5o0fyxfNcWgPjdcqM8pilKYiPyn9yz2QUYG7rTEzTay/52RfxrwLfA/YNuCOoB0Wt8BT3jIKEqEXx02jaOAvYFJSJnyOhWQzucttEN3IUJ9zpeIZvlchJ8+Q+VzIRU6AblYnwVm9khzOd3Dyxeb34ssafc0ccsD6qj4oTaun98ijc8DlriDzPHZjPwLgG2A/yC2hGJ2HUXajzXAPKQR/C/wOfAUcHB+USq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W+SeG9guacjQ8gxk4C/Im/qhLzD72Afal2SSBOZsFmpvFfTe8PGsnWqkjptHFFt3UPz6h9kg9VLkUW1oSjDrjsjNk1PCz1A9kaqZVLW9VsF+yHTQrMCyWtzu9ov6nPFUZ8bp6n9XBcnGgXOr+JkNXE58DJhv1U7SNRp47bXfZm0wXehPeUcNNro2225FttSzlC00RcqZzX1DVG3Ha17RRlO1LcVRVBfUBRFURRFURRFURRFURRFURRFURRFURRFURRFURTg/4+VR9X8IeyTAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$- \\gamma {u}_{k - 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": 151,
     "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",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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
}
