---
jupytext:
  formats: ipynb,md:myst,py:light
  text_representation:
    extension: .md
    format_name: myst
    format_version: 0.13
    jupytext_version: 1.13.8
kernelspec:
  display_name: Python 3
  language: python
  name: python3
---

```{code-cell}
:tags: [hide-cell]

import mmf_setup; mmf_setup.nbinit()
import os
from pathlib import Path
FIG_DIR = Path(mmf_setup.ROOT) / '../Docs/_build/figures/'
os.makedirs(FIG_DIR, exist_ok=True)
import logging; logging.getLogger("matplotlib").setLevel(logging.CRITICAL)
%matplotlib inline
import numpy as np, matplotlib.pyplot as plt
try: from myst_nb import glue
except: glue = None
```

(sec:PDEs)=
# 9. Partial Differential Equations (PDEs)

The theory of general PDEs is much less well-developed than that for ODEs, so we will
restrict our attention to a few special cases that appear in physics.  These tend to
include linear PDEs up to second order including the following:
1. **Wave equation**:
   \begin{gather*}
     \left(\nabla^2 - \frac{1}{c^2}\pdiff[2]{}{t}\right)\psi = 0.
   \end{gather*}
   This is an example of a **hyperbolic** equation amenable to solution by the **method
   of characteristics** with general solutions that move with speed $c = \norm{\vect{v}}_{2}$:
   \begin{gather*}
     \psi(x, t) = f(\vect{x} - \vect{v} t)
   \end{gather*}
   for any initial shape $f(\vect{x})$.  I.e., the shape does not change.
2. **Laplace's equation**:
   \begin{gather*}
     \nabla^2\psi = 0.
   \end{gather*}
   This is an example of an **elliptic equation** has the nice property that specifying
   the solution $\phi(\vect{x})$ on the boundary of a region $\partial V$ defines the
   solution everywhere in the interior.  This solution can be found by **relaxation**.
   The inhomogeneous form is **Poisson's equation**
   \begin{gather*}
     \nabla^2\psi = -\frac{\rho}{\epsilon_0}.
   \end{gather*}
   Example: $\psi$ is the electrostatic potential due to a spatial charge distribution
   $\rho$.
3. **Diffusion equation**:
   \begin{gather*}
     \left(\nabla^2 - \frac{1}{\kappa}\pdiff{}{t}\right)\psi = 0.
   \end{gather*}
   Example: If $\psi$ is the temperature, this is called the **heat equation** and
   $\kappa$ is the thermal conductivity.  This is the prototypical example of a
   **parabolic equation**.
4. **Schrödinger equation**:
   \begin{gather*}
     \left(\frac{-\hbar^2}{2m}\nabla^2 + V - \I\hbar\pdiff{}{t}\right)\psi = 0.
   \end{gather*}
   This is very closely related to the heat equation, but complex coefficients.

## Elliptic, Hyperbolic, and Parabolic

A big problem is to determine the existence and uniqueness of a solution given set of
boundary conditions.  For second-order linear equations:
\begin{gather*}
  \sum_{ij} \frac{\partial^2 \psi}{\partial x_i\partial x_j} 
  = A_{ij}\partial_{i}\partial_{j}\psi 
  = A_{ij}\psi_{,ij} = f(\vect{x}, \vect{\nabla}\psi),
\end{gather*}
the nature of the system is given by the eigenvalues of the matrix $\mat{A}$.
* **Elliptic**: All eigenvalues are non-zero and have the same sign.
* **Parabolic** One eigenvalue is zero and all others have the same sign.
* **Hyperbolic** All eigenvalues are non-zero and one has the opposite sign of the rest.
* **Ultrahyperbolic** All eigenvalues are non-zero and more than one has the opposite
  sign as the rest. *(At least two positive and at least two negative.)*

Each of these has different requirements for sufficient boundary conditions (see e.g. Table
9.1 in {cite}`Arfken:2013`), but you should use your physical intuition to guide you:

* **Elliptic** equations are like Laplace's equation where specifying the function
  (**Dirichlet** or **Neumann**) on a closed boundary suffices.
* **Parabolic** equations are like the heat-equation where specifying the boundary
  conditions on the outside of a box and at some time in the past is sufficient.
  (I.e. **Dirichlet** or **Neumann** conditions on an open boundary fixes the solution
  in the time-direction.)
* **Hyperbolic** equations are like the wave-equation.  If you specify the solution and
  its derivative along an open surface, then this solution will propagate along the
  characteristics.  *(Note that **Cauchy** conditions are needed here since there are two
  possible solution traveling along orthogonal characteristics.  Thus, we need both
  values and derivatives (perpendicular to the surface) in order to uniquely specify
  the linear combination of these.)*


## Inhomogeneous PDEs

To solve inhomogeneous linear PDE
\begin{gather*}
  \op{\mathcal{L}}\psi(\vect{x}) = f(\vect{x}),
\end{gather*}
the method of choice is to find a **Green's functions** $G(\vect{x})$ such that
\begin{gather*}
  \op{\mathcal{L}}G(\vect{x}) = \delta(\vect{x}).
\end{gather*}
An inhomogeneous solution can then be directly constructed by convolution:
\begin{gather*}
  \psi(\vect{x}) = G*f = \int G(\vect{x} - \vect{y})f(\vect{y})\d\vect{y}
\end{gather*}
and the general solution found by adding the homogeneous solutions.  Note: due to this
degeneracy, the choice of Green's function is not unique and is usually motivated by
boundary conditions.

## Non-linear PDEs

Non-linear PDEs can often be approximated locally by a linear PDE, allowing for a local
characterization of the solution.  A fun example is provided by the {ref}`sec:Traffic`
model:
\begin{gather*}
  \pdiff{n}{t} + \pdiff{nu(n)}{x} = 0
\end{gather*}
where $u(n)$ is some function characterizing the speed of traffic give a local traffic
density $n$.


[Fuch's theorem]: <https://en.wikipedia.org/wiki/Fuchs's_theorem>
[method of undetermined coefficients]: <https://en.wikipedia.org/wiki/Method_of_undetermined_coefficients>
[delta function]: <https://en.wikipedia.org/wiki/Dirac_delta_function>
[Riemann-Stieltjes Integral]: <https://en.wikipedia.org/wiki/Riemann%E2%80%93Stieltjes_integral>
[Heaviside step function]: <https://en.wikipedia.org/wiki/Heaviside_step_function>
[distribution]: <https://en.wikipedia.org/wiki/Distribution_(mathematics)>
[variation of parameters]: <https://en.wikipedia.org/wiki/Variation_of_parameters>
[Wronskian]: <https://en.wikipedia.org/wiki/Wronskian>
[osculating]: <https://en.wikipedia.org/wiki/Osculating_curve>
[integrating factor]: <https://en.wikipedia.org/wiki/Integrating_factor>
[envelope]: <https://en.wikipedia.org/wiki/Envelope_(mathematics)>
