{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c6805951",
   "metadata": {},
   "source": [
    "# Multidimensional differential equations\n",
    "\n",
    "- Börge Göbel "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "921259c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt \n",
    "from scipy import integrate"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29eb17ec",
   "metadata": {},
   "source": [
    "## Heat equation"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a0e04d81",
   "metadata": {},
   "source": [
    "We solve the differential equations:\n",
    "\n",
    "\\\\( \n",
    "\\frac{\\partial}{\\partial t} u(\\vec{r},t) = a \\Delta u(\\vec{r},t)\n",
    "\\\\)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b461fb52",
   "metadata": {},
   "source": [
    "## In one dimension:\n",
    "\n",
    "\\\\( \n",
    "\\frac{\\partial}{\\partial t} u(x,t) = a \\frac{\\partial^2}{\\partial x^2} u(x,t)\n",
    "\\\\)\n",
    "\n",
    "Here, \\\\( u(x,t) \\\\) is an array \\\\(\\{ u_1, u_2, \\dots, u_n \\} \\\\) that has different values for different times. It describes the temperature. We can discretize the spatial derivative according to:\n",
    "\n",
    "\\\\( \n",
    "\\frac{\\partial^2}{\\partial x^2} u_j = \\frac{u_{j+1}-2u_{j}+u_{j-1}}{(\\Delta x)^2}\n",
    "\\\\)\n",
    "\n",
    "For the edges we use double-forward or double-backward methods:\n",
    "\n",
    "\\\\( \n",
    "\\frac{\\partial^2}{\\partial x^2} u_1 = \\frac{u_{1}-2u_{2}+u_{3}}{(\\Delta x)^2}\\\\\n",
    "\\frac{\\partial^2}{\\partial x^2} u_n = \\frac{u_{n}-2u_{n-1}+u_{n-2}}{(\\Delta x)^2}\n",
    "\\\\)\n",
    "\n",
    "We can rewrite the heat equation as a set of coupled equation:\n",
    "\n",
    "\\begin{align}\n",
    "\\frac{\\partial}{\\partial t}u_1&=\\frac{a}{(\\Delta x)^2}\\left(u_1-2u_2+u_3\\right)\\\\\n",
    "\\frac{\\partial}{\\partial t}u_2&=\\frac{a}{(\\Delta x)^2}\\left(u_1-2u_2+u_3\\right)\\\\\n",
    "\\frac{\\partial}{\\partial t}u_3&=\\frac{a}{(\\Delta x)^2}\\left(u_2-2u_3+u_4\\right)\\\\ \n",
    "\\vdots\\\\ \n",
    "\\frac{\\partial}{\\partial t}u_j&=\\frac{a}{(\\Delta x)^2}\\left(u_{j-1}-2u_j+u_{j+1}\\right)\\\\ \n",
    "\\vdots\\\\\n",
    "\\frac{\\partial}{\\partial t}u_{n-2}&=\\frac{a}{(\\Delta x)^2}\\left(u_{n-3}-2u_{n-2}+u_{n-1}\\right)\\\\\n",
    "\\frac{\\partial}{\\partial t}u_{n-1}&=\\frac{a}{(\\Delta x)^2}\\left(u_{n-2}-2u_{n-1}+u_{n}\\right)\\\\\n",
    "\\frac{\\partial}{\\partial t}u_n&=\\frac{a}{(\\Delta x)^2}\\left(u_{n-2}-2u_{n-1}+u_{n}\\right)\n",
    "\\end{align}\n",
    "\n",
    "Alternatively, we can also keep the temperature at the edges constant and consider these to be (part of) the constant heat bath:\n",
    "\n",
    "\\\\( u_1 = \\mathrm{const.}\\\\ u_n = \\mathrm{const.} \\\\)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6f5934d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "1a95b3a3",
   "metadata": {},
   "source": [
    "### Different starting parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e62f363",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "81519a01",
   "metadata": {},
   "source": [
    "## In 2 dimensions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46cfdb1d",
   "metadata": {},
   "source": [
    "\\\\( \n",
    "\\frac{\\partial}{\\partial t} u(\\vec{r},t) = a \\left(\\frac{\\partial^2}{\\partial x^2} u(\\vec{r},t) + \\frac{\\partial^2}{\\partial y^2} u(\\vec{r},t)\\right)\n",
    "\\\\)\n",
    "\n",
    "Here, \\\\( u(\\vec{r},t) \\\\) is an array \\\\(\\{ u_{1,1}, u_{1,2}, \\dots, u_{n,n} \\} \\\\) that has different values for different times. We can discretize the spatial derivative according to:\n",
    "\n",
    "\\\\( \n",
    "\\frac{\\partial^2}{\\partial x^2} u_{i,j} + \\frac{\\partial^2}{\\partial y^2} u_{i,j} = \\frac{u_{i+1,j}-2u_{i,j}+u_{i-1,j}}{(\\Delta x)^2}+\\frac{u_{i,j+1}-2u_{i,j}+u_{i,j-1}}{(\\Delta y)^2}\n",
    "\\\\)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb56f75e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "afb7489d",
   "metadata": {},
   "source": [
    "### Different starting conditions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd6f4fac",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
