---
jupytext:
    formats: md:myst
    text_representation:
        extension: .md
        format_name: myst
kernelspec:
    display_name: Python 3 (ipykernel)
    language: python
    name: python3
---
(app:eqsconstants)=
# Some equations and constants

## Physical constants
```{table} Some physical constants with their values in standard units.
:name: table:physicalconstants
| **Name** | **Symbol** | **Value** |
| :--- | :--: | :--- |
| Speed of light | $c$ | $3.00 \cdot 10^{8}\;\mathrm{m}/\mathrm{s}$ |
| Elementary charge | $e$ | $1.60 \cdot 10^{-19}\;\mathrm{C}$ |
| Electron mass | $m_e$ | $9.11 \cdot 10^{-31}\;\mathrm{kg} = 0.511\;\mathrm{MeV}/c^2$ |
| Proton mass | $m_p$ | $1.67 \cdot 10^{-27}\;\mathrm{kg} = 938\;\mathrm{MeV}/c^2$ |
| Gravitational constant | $G$ | $6.67 \cdot 10^{-11}\;\mathrm{N}\cdot\mathrm{m}^2/\mathrm{kg}^2$|
| Planck's constant | $h$ | $6.63 \cdot 10^{-34}\;\mathrm{J}\cdot\mathrm{s}$|
| | $\hbar = h / 2 \pi$ | $1.05 \cdot 10^{-34}\;\mathrm{J}\cdot\mathrm{s}$|
| Permittivity of space | $\varepsilon_0$ | $8.85419 \cdot 10^{-12}\;\mathrm{C}^2/\mathrm{J}\cdot\mathrm{m}$|
| Boltzmann's constant | $\kB$ | $1.38 \cdot 10^{-23}\;\mathrm{J}/\mathrm{K}$|
| Bohr radius | $a$ | $\frac{4\pi \varepsilon_0 \hbar^2}{e^2 m_\mathrm{e}} = 5.29177 \cdot 10^{-11}\;\mathrm{m}$ |
| Fine structure constant | $\alpha$ | $\frac{e^2}{4\pi\varepsilon_0 \hbar c} = \frac{1}{137.036}$ |
| Rydberg energy | $R_\mathrm{E}$ | $\frac{e^4 m_\mathrm{e}}{2(4\pi\varepsilon_0 \hbar)^2} = \frac12 \left(m_\mathrm{e} c^2\right) \alpha^2 = 13.6057\;\mathrm{eV}$.|
```

## Wave-particle duality
The de Broglie energy and momentum are given by:
```{math}
:label: deBrogliephotonenergy
\begin{align*}
E &= h f = \hbar \omega, 
\end{align*}
```

```{math}
:label: deBrogliephotonmomentum
\begin{align*}
p &= h/\lambda = \hbar k.
\end{align*}
```

## Schr&ouml;dinger equation
The general Schr&ouml;dinger equation in three dimensions is given by:

$$
i \hbar \frac{\partial \Psi(\bm{x}, t)}{\partial t} = - \frac{\hbar^2}{2m} \nabla^2 \Psi(\bm{x}, t) + V(\bm{x}) \Psi(\bm{x}, t).
$$ (3DSchrodinger)

In one dimension, the time-independent version of the Schr&ouml;dinger equation is:

$$
\hat{H} \psi(x) = -\frac{\hbar^2}{2m} \frac{\mathrm{d}^2 \psi(x)}{\mathrm{d}x^2} + V(x) \psi(x) = E \psi(x).
$$ (1DSchrodinger)

## Operators
The position and momentum operators are given by
```{math}
:label: positionoperator-appendix
\begin{align*}
\hat{x} \Psi(x,t) &= x \Psi(x,t), 
\end{align*}
```

```{math}
:label: momentumoperator-appendix
\begin{align*}
\hat{p} \Psi(x,t) &= - i \hbar \frac{\partial \Psi(x,t)}{\partial x}.
\end{align*}
```
The expectation value of any operator $\hat{Q}$ can be calculated through

$$
\Braket{\hat{Q}} = \int_{-\infty}^\infty \Psi^*(x,t) \hat{Q} \Psi(x,t) \,\mathrm{d}x.
$$ (expectationvalues)

The commutator $\left[ \hat{A}, \hat{B} \right]$ of two operators is defined as

$$
\left[ \hat{A}, \hat{B} \right] = \hat{A}\hat{B} - \hat{B}\hat{A}.
$$ (commutoator-appendix)

For any two Hermitian operators $\hat{A}$ and $\hat{B}$, we have the general uncertainty principle

$$
\sigma_A \sigma_B \geq \left| \frac{1}{2i} \Braket{\left[ \hat{A}, \hat{B} \right]} \right|.
$$ (uncertaintyprinciple-appendix)

The time evolution of the expectation value of an operator is given by

$$
\frac{\mathrm{d}}{\mathrm{d}t} \Braket{\hat{Q}} = \frac{i}{\hbar} \Braket{\left[ \hat{H}, \hat{Q} \right]} + \Braket{ \frac{\partial \hat{Q}}{\partial t}},
$$ (expectationtimeevolution)

where $\hat{H}$ is the Hamiltonian of the system.

## Spin
The operators for the $x$, $y$ and $z$ component of the spin satisfy the commutation relations

```{math}
:label: spincommutators-appendix
\begin{align*}
\left[ \hat{S}_x, \hat{S}_y \right] &= i \hbar \hat{S}_z, \\
\left[ \hat{S}_y, \hat{S}_z \right] &= i \hbar \hat{S}_x, \\
\left[ \hat{S}_z, \hat{S}_x \right] &= i \hbar \hat{S}_y.
\end{align*}
```

For a spin-1/2 particle in the basis of the eigenvectors $\chi_{+} = \left(\begin{array}{c}1\\ 0 \end{array}\right)$ and $\chi_{-} = \left(\begin{array}{c}0\\ 1 \end{array}\right)$ of the $\hat{S}_z$ operator, the spin operators are given by the matrix expressions:

```{math}
:label: spinmatrices
\begin{align*}
\hat{S}_x &= \frac{\hbar}{2} \hat{\bm{\sigma}}_x = \frac{\hbar}{2} \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, \\
\hat{S}_y &= \frac{\hbar}{2} \hat{\bm{\sigma}}_y = \frac{\hbar}{2} \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}, \\
\hat{S}_z &= \frac{\hbar}{2} \hat{\bm{\sigma}}_z = \frac{\hbar}{2} \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix},
\end{align*}
```


(sec:hydrogenwavefunctions)=
## Hydrogen wavefunctions

(sec:sphericalharmonicstable)=
### Spherical harmonics

The spherical harmonics, or Fourier modes on the sphere, are given by (equation&nbsp;{eq}`sphericalharmonics`):

$$
Y_l^m(\theta, \phi) = \varepsilon \sqrt{\frac{2l+1}{4\pi} \frac{(l-|m|)!}{(l+|m|)!}} P_l^m(\cos\theta) e^{im\phi},
$$ (sphericalharmonicsrepeat)

where $\varepsilon = 1$ if $m \leq 0$ and $\varepsilon = (-1)^m$ if $m>0$. The $P_l^m(x)$ are the associated Legendre functions, defined by (equation&nbsp;{eq}`assocLegendrepolynomialdef`):

$$
P_l^m(x) = (1-x^2)^{|m|/2} \left( \frac{\mathrm{d}}{\mathrm{d}x}\right)^{|m|} P_l(x),
$$ (assocLegendrepolynomialdefrepeat)

for any integer&nbsp;$m$ (but zero if $|m| > l$). The Legendre polynomials $P_l(x)$ are most easily found using the Rodriguez formula, equation&nbsp;{eq}`RodriguezformulaLegendrepolynomials`:

$$
P_l(x) = \frac{1}{2^l l!} \left( \frac{\mathrm{d}}{\mathrm{d}x}\right)^l (x^2-1)^l,
$$ (RodriguezformulaLegendrepolynomialsrepeat)

for any non-negative integer value of $l$. The first six Legendre polynomials are:

```{math}
:label: Legendrepolynomialslist
\begin{align*}
P_0(x) &= 1 \\
P_1(x) &= x \\
P_2(x) &= \frac12 \left(3 x^2 - 1\right) \\
P_3(x) &= \frac12 \left(5 x^3 - 3x\right) \\
P_4(x) &= \frac18 \left(35 x^4 - 30 x^2 + 3\right) \\
P_5(x) &= \frac18 \left(63 x^5 - 70 x^3 + 15x\right)
\end{align*}
```

```{code-cell} ipython3
:tags: [hide-input, remove-output]

%config InlineBackend.figure_formats = ['svg']
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import legendre
from myst_nb import glue

x = np.linspace(-1, 1, 200)

fig, ax = plt.subplots(figsize=(6,4))

ax.axhline(y = 0, color = 'k', linestyle = ':')

for n in np.arange(0, 6):
    ax.plot(x, legendre(n)(x), label=rf'$P_{n}$')

ax.set_xlim(-1, 1)
ax.set_ylim(-1.1, 1.1)
ax.set_xlabel('$x$')
ax.set_ylabel('$P_{n}$')
ax.legend()
# Save graph to load in figure later (special Jupyter Book feature)
glue("Legendrepolynomials-appendix", fig, display=False)
```

```{glue:figure} Legendrepolynomials-appendix
:name: fig:Legendrepolynomials-appendix
The first six Legendre polynomials.
```

The associated Legendre functions up to $l=3$, expressed as a function of $\cos(\theta)$, are:

```{math}
:label: AssociatedLegendrepolynomialslist
\begin{align*}
P_0^0(\cos(\theta)) &= 1 \\
P_1^0(\cos(\theta)) &= \cos(\theta) \\
P_1^1(\cos(\theta)) &= \sin(\theta) \\
P_2^0(\cos(\theta)) &= \frac12 \left(3\cos^2(\theta) - 1 \right) \\
P_2^1(\cos(\theta)) &= -3 \sin(\theta) \cos(\theta) \\
P_2^2(\cos(\theta)) &= 3 \sin^2(\theta) \\
P_3^0(\cos(\theta)) &= \frac12 \left(5\cos^3(\theta) - 3 \cos(\theta) \right) \\
P_3^1(\cos(\theta)) &= -\frac32 \sin(\theta) \left( 5\cos^2(\theta) - 1\right) \\
P_3^2(\cos(\theta)) &= 15 \sin^2(\theta) \cos(\theta) \\
P_3^3(\cos(\theta)) &= -15 \sin(\theta) \left(1 - \cos^2(\theta)\right)
\end{align*}
```

```{code-cell} ipython3
:tags: [hide-input, remove-output]

%config InlineBackend.figure_formats = ['svg']
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import assoc_legendre_p as assoclegendre
from myst_nb import glue

def P00(theta):
    # Returns the associated Legendre function P_0^0(theta).
    return np.ones(len(theta))

def P10(theta):
    # Returns the associated Legendre function P_1^0(theta).
    return np.cos(theta)

def P11(theta):
    # Returns the associated Legendre function P_1^1(theta).
    return np.sin(theta)

def P20(theta):
    # Returns the associated Legendre function P_2^0(theta).
    return 0.5 * (3 * np.cos(theta)*np.cos(theta) - 1)

def P21(theta):
    # Returns the associated Legendre function P_2^1(theta).
    return -3*np.sin(theta)*np.cos(theta)

def P22(theta):
    # Returns the associated Legendre function P_2^2(theta).
    return 3*np.sin(theta)*np.sin(theta)

theta = np.linspace(0, 2*np.pi, 400)

fig, ax = plt.subplots(figsize=(6,4))

ax.axhline(y = 0, color = 'k', linestyle = ':')

line00 = ax.plot(theta, P00(theta), label='$P_0^0$')
line10 = ax.plot(theta, P10(theta), label='$P_1^0$')
line11 = ax.plot(theta, P11(theta), label='$P_1^1$')
line20 = ax.plot(theta, P20(theta), label='$P_2^0$')
line21 = ax.plot(theta, P21(theta), label='$P_2^1$')
line22 = ax.plot(theta, P22(theta), label='$P_2^2$')

ax.set_xlim(0, 2*np.pi)
ax.set_ylim(-2, 3.1)
ax.set_xlabel('$\\theta$')
ax.set_ylabel('$P_{n}^{m}(\cos(\\theta))$')
ax.set_xticks(np.pi*np.arange(0, 2.25, 0.25))
ax.set_xticklabels([0, '$\\frac{1}{4}\\pi$', '$\\frac{1}{2}\\pi$', '$\\frac{3}{4}\\pi$', '$\\pi$', '$\\frac{5}{4}\\pi$', '$\\frac{3}{2}\\pi$', '$\\frac{7}{4}\\pi$', '$2\\pi$'])
ax.legend(loc='upper right')

# Save graph to load in figure later (special Jupyter Book feature)
glue("associatedLegendrepolynomials-appendix", fig, display=False)
```

```{glue:figure} associatedLegendrepolynomials-appendix
:name: fig:associatedLegendrepolynomials-appendix
The first six associated Legendre functions as functions of the angle $\theta$.
```


Substituting the associated Legendre functions into the expression&nbsp;{eq}`sphericalharmonicsrepeat` for the spherical harmonics, we find up to $l=3$:

```{math}
:label: Sphericalharmonicslist
\begin{align*}
Y_0^0(\theta, \phi) &= \left(\frac{1}{4\pi}\right)^{1/2} \\
Y_1^0(\theta, \phi) &= \left(\frac{3}{4\pi}\right)^{1/2} \cos(\theta) e^{\pm i \phi}\\
Y_1^{\pm 1}(\theta, \phi) &= \mp \left(\frac{3}{8\pi}\right)^{1/2} \sin(\theta) \\
Y_2^0(\theta, \phi) &= \left(\frac{5}{16\pi}\right)^{1/2} \left(3\cos^2(\theta) - 1 \right) \\
Y_2^{\pm 1}(\theta, \phi) &= \mp \left(\frac{15}{8\pi}\right)^{1/2} \sin(\theta) \cos(\theta) e^{\pm i \phi}\\
Y_2^{\pm 2}(\theta, \phi) &= \left(\frac{15}{32\pi}\right)^{1/2} \sin^2(\theta) e^{\pm 2i \phi}\\
Y_3^0(\theta, \phi) &= \left(\frac{7}{16\pi}\right)^{1/2} \left(5\cos^3(\theta) - 3 \cos(\theta) \right) \\
Y_3^{\pm 1}(\theta, \phi) &= \mp \left(\frac{21}{64\pi}\right)^{1/2} \sin(\theta) \left( 5\cos^2(\theta) - 1\right) e^{\pm i \phi}\\
Y_3^{\pm 2}(\theta, \phi) &= \left(\frac{105}{32\pi}\right)^{1/2} \sin^2(\theta) \cos(\theta) e^{\pm 2i \phi}\\
Y_3^{\pm 3}(\theta, \phi) &= \mp \left(\frac{35}{64\pi}\right)^{1/2} \sin(\theta) \left(1 - \cos^2(\theta)\right) e^{\pm 3i \phi}
\end{align*}
```

### Radial part of the hydrogen wavefunction
Specifically for the hydrogen atom, the radial part of the wavefunction is given in terms of the associated Laguerre polynomials, given by (equation&nbsp;{eq}`Laguerrepolynomials`):

```{math}
:label: Laguerrepolynomialsrepeat
\begin{align*}
L_q^p(x) &= (-1)^p \left(\frac{\mathrm{d}}{\mathrm{d}x}\right)^p L_{p+q}(x) = \frac{x^{-p} e^x}{q!} \left(\frac{\mathrm{d}}{\mathrm{d}x}\right)^q \left( e^{-x} x^{p+q} \right), \\
L_q(x) &= \frac{e^x}{q!} \left(\frac{\mathrm{d}}{\mathrm{d}x}\right)^q \left( e^{-x} x^q \right).
\end{align*}
```

The first six Laguerre polynomials are:

```{math}
:label: Laguerrepolynomialslist
\begin{align*}
L_0(x) &= 1 \\
L_1(x) &= -x + 1 \\
L_2(x) &= \frac12 \left(x^2 - 4x + 2 \right)\\
L_3(x) &= \frac16 \left(-x^3 + 9 x^2 - 18x + 6 \right)\\
L_4(x) &= \frac{1}{24} \left(x^4 - 16 x^3 + 72 x^2 - 96x + 24 \right)\\
L_5(x) &= \frac{1}{120} \left(-x^5 + 25 x^4 - 200 x^3 + 600 x^2 - 600 x + 120 \right)
\end{align*}
```

```{code-cell} ipython3
:tags: [hide-input, remove-output]

%config InlineBackend.figure_formats = ['svg']
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import laguerre
from myst_nb import glue

x = np.linspace(0, 5, 500)

fig, ax = plt.subplots(figsize=(6,4))

ax.axhline(y = 0, color = 'k', linestyle = ':')

for n in np.arange(0, 6):
    ax.plot(x, laguerre(n)(x), label=rf'$L_{n}$')

ax.set_xlim(0,5)
ax.set_ylim(-2.0,4.0)
ax.set_xlabel('$x$')
ax.set_ylabel('$L_{q}$')
ax.legend()
# Save graph to load in figure later (special Jupyter Book feature)
glue("Laguerrepolynomials-appendix", fig, display=False)
```

```{glue:figure} Laguerrepolynomials-appendix
:name: fig:Laguerrepolynomials-appendix
The first six Laguerre polynomials.
```

For the associated Laguerre polynomials up to $q = 3$ we find:

```{math}
:label: associatedLaguerrepolynomialslist
\begin{align*}
L_0^p(x) &= 1 \\
L_1^p(x) &= -x + p + 1 \\
L_2^p(x) &= \frac{1}{2} \left(p^2-2 p x+3 p+x^2-4 x+2\right)\\
L_3^p(x) &= \frac16 \left(p^3-3 p^2 x+6 p^2+3 p x^2-15 p x+11 p-x^3+9 x^2-18 x+6\right)
\end{align*}
```

```{code-cell} ipython3
:tags: [hide-input, remove-output]

%config InlineBackend.figure_formats = ['svg']
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import genlaguerre
from myst_nb import glue

x = np.linspace(0, 10, 1000)

fig, ax = plt.subplots(figsize=(6,4))

ax.axhline(y = 0, color = 'k', linestyle = ':')

for n in np.arange(0, 4):
    for p in np.arange(0, n+1):
        ax.plot(x, genlaguerre(n, p)(x), label=rf'$L_{n}^{p}$')

ax.set_xlim(0,10)
ax.set_ylim(-4.0,8.0)
ax.set_xlabel('$x$')
ax.set_ylabel('$L_{q}$')
ax.legend()
# Save graph to load in figure later (special Jupyter Book feature)
glue("associatedLaguerrepolynomials-appendix", fig, display=False)
```

```{glue:figure} associatedLaguerrepolynomials-appendix
:name: fig:associatedLaguerrepolynomials-appendix
The first ten associated Laguerre polynomials.
```

The (normalized) first ten radial wave functions for hydrogen are given by

```{math}
:label: hydrogenradialwavefunctionsrepeat
\begin{align*}
R_{10}(r) &= \frac{2}{\sqrt{a_0^3}} e^{-r/a_0}, \\
R_{20}(r) &= \frac{1}{\sqrt{2 a_0^3}} \left(1-\frac{r}{2 a_0} \right) e^{-r/2a_0}, \\
R_{21}(r) &= \frac{1}{\sqrt{6 a_0^3}} \left(\frac{r}{2 a_0} \right) e^{-r/2a_0}, \\
R_{30}(r) &= \frac{2}{3\sqrt{3 a_0^3}} \left(1 - \frac{2r}{3 a_0} + \frac23 \left(\frac{r}{3 a_0}\right)^2 \right) e^{-r/3a_0}, \\
R_{31}(r) &= \frac{8}{9\sqrt{6 a_0^3}} \left(1 - \frac12 \frac{r}{3 a_0} \right) \left( \frac{r}{3 a_0} \right)  e^{-r/3a_0}, \\
R_{32}(r) &= \frac{4}{9\sqrt{30 a_0^3}} \left( \frac{r}{3 a_0} \right)^2  e^{-r/3a_0}, \\
R_{40}(r) &= \frac{1}{4\sqrt{3 a_0^3}} \left(1 - \frac{3r}{4a_0} + 2 \left(\frac{r}{4a_0}\right)^2 - \frac13 \left(\frac{r}{4a_0}\right)^3 \right) e^{-r/4a_0}, \\
R_{41}(r) &= \frac{5}{4\sqrt{15 a_0^3}} \left(1 - \frac{r}{4a_0} + \frac15 \left(\frac{r}{4a_0}\right)^2 \right) \left(\frac{r}{4a_0}\right) e^{-r/4a_0}, \\
R_{42}(r) &= \frac{1}{4\sqrt{5 a_0^3}} \left(1 - \frac13 \frac{r}{4a_0} \right) \left( \frac{r}{4a_0} \right)^2  e^{-r/4a_0}, \\
R_{43}(r) &= \frac{1}{12\sqrt{35 a_0^3}} \left( \frac{r}{4a_0} \right)^3  e^{-r/4a_0}.
\end{align*}
```

```{code-cell} ipython3
:tags: [hide-input, remove-output]

%config InlineBackend.figure_formats = ['svg']
import numpy as np
import matplotlib.pyplot as plt
from myst_nb import glue

def R10(r):
    # Returns R_{10}(r), with r in units of the Bohr radius.
    return 2 * np.exp(-r)

def R20(r):
    # Returns R_{20}(r), with r in units of the Bohr radius.
    return (1 / np.sqrt(2)) * (1 - r/2) * np.exp(-r/2)

def R21(r):
    # Returns R_{21}(r), with r in units of the Bohr radius.
    return (1/np.sqrt(6)) * (r/2) * np.exp(-r/2)

def R30(r):
    # Returns R_{30}(r), with r in units of the Bohr radius.
    return (2 / np.sqrt(27)) * (1 - (2*r/3) + (2/3) * pow(r/3, 2)) * np.exp(-r/3)

def R31(r):
    # Returns R_{31}(r), with r in units of the Bohr radius.
    return (8/np.sqrt(486)) * (1- r/6) * (r/3) * np.exp(-r/3)

def R32(r):
    # Returns R_{32}(r), with r in units of the Bohr radius.
    return (4/np.sqrt(2430)) * pow(r/3,2) * np.exp(-r/3)

def R40(r):
    # Returns R_{40}(r), with r in units of the Bohr radius.
    return (0.25 / np.sqrt(3)) * (1 - (3*r/4) + 2 * pow(r/4, 2) - (1/3) * pow(r/4, 3)) * np.exp(-r/4)

def R41(r):
    # Returns R_{41}(r), with r in units of the Bohr radius.
    return (1.25/np.sqrt(15)) * (1- r/4 + 0.2 * pow(r/4, 2)) * (r/4) * np.exp(-r/4)

def R42(r):
    # Returns R_{42}(r), with r in units of the Bohr radius.
    return (0.25/np.sqrt(5)) * (1 - r/12) * pow(r/4,2) * np.exp(-r/4)

def R43(r):
    # Returns R_{43}(r), with r in units of the Bohr radius.
    return (1/(12*np.sqrt(35))) * pow(r/4, 3) * np.exp(-r/4)


r = np.linspace(0, 10, 1000)

fig, ax = plt.subplots(figsize=(6,4))

line10 = ax.plot(r, R10(r), label='$R_{10}(r)$')
line20 = ax.plot(r, R20(r), label='$R_{20}(r)$')
line21 = ax.plot(r, R21(r), label='$R_{21}(r)$')

line30 = ax.plot(r, R30(r), label='$R_{30}(r)$')
line31 = ax.plot(r, R31(r), label='$R_{31}(r)$')
line32 = ax.plot(r, R32(r), label='$R_{32}(r)$')

line40 = ax.plot(r, R40(r), label='$R_{40}(r)$')
line41 = ax.plot(r, R41(r), label='$R_{41}(r)$')
line42 = ax.plot(r, R42(r), label='$R_{42}(r)$')
line43 = ax.plot(r, R43(r), label='$R_{43}(r)$')

ax.axhline(y = 0, color = 'k', linestyle = ':')

ax.set_xlim(0,10)
ax.set_ylim(-0.15,0.4)
ax.set_xlabel('$r/a_0$')
ax.set_ylabel('$R_{nl}$')
ax.legend()
# Save graph to load in figure later (special Jupyter Book feature)
glue("hydrogenradialfunctions-appendix", fig, display=False)
```

```{glue:figure} hydrogenradialfunctions-appendix
:name: fig:hydrogenradialfunctions-appendix
Radial part of the first ten eigenfunctions of the hydrogen Hamiltonian.
```


## Mathematical identities
### Goniometric functions
```{math}
\begin{align*}
e^{i\phi} &= \cos(\phi) + i \sin(\phi) \\
\sin(\phi) &= \frac{1}{2i} \left( e^{i \phi} - e^{-i \phi} \right) \\
\cos(\phi) &= \frac12 \left( e^{i \phi} + e^{-i \phi} \right) \\
1 &= \sin^2(\phi) + \cos^2(\phi) \\
\sin(2 \phi) &= 2 \sin(\phi) \cos(\phi)\\
\cos(2\phi) &= \cos^2(\phi)-\sin^2(\phi) \\
\sin(a \pm b) &= \sin(a) \cos(b) \pm \sin(b) \cos(a) \\
\cos(a \pm b) &= \cos(a) \cos(b) \pm \sin(a) \sin(b)
\end{align*}
```

### Some goniometric integrals
The following hold for any integers $m$ and $n$.
```{math}
\begin{align*}
\int_0^L \sin\left(\frac{m \pi x}{L} \right) \sin\left(\frac{n \pi x}{L} \right) \,\mathrm{d}x &= \frac{L}{2} \delta_{mn}.\\
\int_0^L \cos\left(\frac{m \pi x}{L} \right) \cos\left(\frac{n \pi x}{L} \right) \,\mathrm{d}x &= \frac{L}{2} \delta_{mn}. \\
\int_0^L \sin\left(\frac{n \pi x}{L} \right) \cos\left(\frac{n \pi x}{L} \right) \,\mathrm{d}x &= 0. \\
\int_0^L \sin\left(\frac{m \pi x}{L} \right) \cos\left(\frac{n \pi x}{L} \right) \,\mathrm{d}x &= \frac{1-(-1)^{m+n}}{m^2-n^2} \frac{L m}{\pi}. \\
\int_0^L x \sin^2\left(\frac{n \pi x}{L} \right) \,\mathrm{d}x = \int_0^L x \cos^2\left(\frac{n \pi x}{L} \right) \,\mathrm{d}x &= \frac{L^2}{4}. \\
\int_0^L x \sin\left(\frac{\pi x}{L} \right) \sin\left(\frac{2 \pi x}{L} \right) \,\mathrm{d}x &= - \frac{8 L^2}{9 \pi^2}. \\
\int_0^L x \cos\left(\frac{\pi x}{L} \right) \cos\left(\frac{2 \pi x}{L} \right) \,\mathrm{d}x &= - \frac{10 L^2}{9 \pi^2}. \\
\int_0^L x \sin\left(\frac{n \pi x}{L} \right) \cos\left(\frac{n \pi x}{L} \right) \,\mathrm{d}x &= -\frac{L^2}{4 n \pi}.
\end{align*}
```
For any $a \neq 0$, we have the indefinite integrals
```{math}
\begin{align*}
\int x \sin(ax) \,\mathrm{d}x &= \frac{1}{a^2} \sin(ax) - \frac{x}{a} \cos(ax), \\
\int x \cos(ax) \,\mathrm{d}x &= \frac{1}{a^2} \cos(ax) + \frac{x}{a} \sin(ax).
\end{align*}
```

### Exponential integrals

$$
\int_0^\infty x^n e^{-x/a} \,\mathrm{d}x = n!\, a^{n+1} \qquad \text{for any integer }  n.
$$ (expintegral)

### Some Gaussian integrals
Gaussian integrals are integrals over the Gaussian distribution $\exp(-x^2)$ (aka the normal distribution). In general, these cannot be evaluated in closed form, and we define the *error function* as the integral:

$$
\mathrm{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{-y^2} \,\mathrm{d}y.
$$ (errorfunction)

There are however a number of Gaussian integrals that can be evaluated explicitly: those over all of&nbsp;$\mathbb{R}$. Of course, as the Gaussian distribution is symmetric, we can also find the integrals from plus or minus infinity to the point of symmetry.

```{math}
:label: Gaussintegral
\begin{align*}
\int_{-\infty}^\infty e^{-a x^2} \,\mathrm{d}x &= \sqrt{\frac{\pi}{a}}. \\
\int_{-\infty}^\infty e^{-a x^2 + b x + c} \,\mathrm{d}x &= \sqrt{\frac{\pi}{a}} \exp\left(\frac{b^2}{4a}+c\right).
\end{align*}
```

```{math}
:label: Gaussxn
\begin{align*}
\int_{-\infty}^\infty x^n e^{-a x^2} \,\mathrm{d}x &= 0 \qquad \text{for any odd value of }  n. \\
\int_{-\infty}^\infty x^n e^{-a x^2} \,\mathrm{d}x &= \frac{1 \cdot 3 \cdot 5 \cdots (n-1) \sqrt{\pi}}{2^{n/2} a^{(n+1)/2}} \qquad \text{for any even value of } n.
\end{align*}
```
Note that we can get&nbsp;{eq}`Gaussxn` by repeated differentiation of&nbsp;{eq}`Gaussintegral` with respect to $a$.

(sec:vectorderivativeexpressions)=
### Vector derivatives

The expressions below are in Cartesian ($x, y, z$), cylindrical ($\rho, \phi, z$) and spherical ($r, \theta, \phi$) coordinates.

**Gradient**:

```{math}
:label: defgradient2
\begin{align*}
\bm{\nabla} f(\bm{r}) &= \bm{\nabla} f(x, y, z) = \begin{pmatrix} \partial_x f \\ \partial_y f \\ \partial_z f \end{pmatrix} = \frac{\partial f}{\partial x} \bm{\hat{x}} + \frac{\partial f}{\partial y} \bm{\hat{y}} + \frac{\partial f}{\partial z} \bm{\hat{z}}, \\
&= \bm{\nabla} f(\rho, \phi, z) = \frac{\partial f}{\partial \rho} \bm{\hat{\rho}} + \frac{1}{\rho} \frac{\partial f}{\partial \phi} \bm{\hat{\phi}} + \frac{\partial f}{\partial z} \bm{\hat{z}}, \\
&= \bm{\nabla} f(r, \theta, \phi) = \frac{\partial f}{\partial r} \bm{\hat{r}} + \frac{1}{r} \frac{\partial f}{\partial \theta} \bm{\hat{\theta}} + \frac{1}{r \sin(\theta)} \frac{\partial f}{\partial \phi} \bm{\hat{\phi}}.
\end{align*}
```

**Divergence**:

```{math}
:label: defdivergence2
\begin{align*}
\bm{\nabla} \cdot \bm{v} &= \left( \partial_x, \partial_y, \partial_z \right) \cdot \begin{pmatrix} v_x \\ v_y \\ v_z \end{pmatrix} = \frac{\partial v_x}{\partial x} + \frac{\partial v_y}{\partial y} + \frac{\partial v_z}{\partial z}, \\
&= \frac{1}{\rho} \frac{\partial }{\partial \rho} \left( \rho v_\rho \right) + \frac{1}{\rho} \frac{\partial v_\phi}{\partial \phi} + \frac{\partial v_z}{\partial z}, \\
&= \frac{1}{r^2} \frac{\partial }{\partial r} \left( r^2 v_r \right) + \frac{1}{r \sin(\theta)} \frac{\partial }{\partial \theta} \left(\sin(\theta) v_\theta\right) + \frac{1}{r \sin(\theta)} \frac{\partial v_\phi}{\partial \phi}.
\end{align*}
```

**Curl**:

```{math}
:label: defcurl2
\begin{align*}
\bm{\nabla} \times \bm{A} &= \left( \partial_x, \partial_y, \partial_z \right) \times \begin{pmatrix} A_x \\ A_y \\ A_z \end{pmatrix} = \begin{pmatrix} \partial_y A_z - \partial_z A_y \\ \partial_z A_x - \partial_x A_z \\ \partial_x A_y - \partial_y A_x \end{pmatrix}, \\
&= \left( \frac{1}{\rho} \frac{\partial v_z}{\partial \phi} - \frac{\partial v_\phi}{\partial z} \right) \bm{\hat{\rho}} + \left( \frac{\partial v_\rho}{\partial z} - \frac{\partial v_z}{\partial \rho} \right) \bm{\hat{\phi}} + \frac{1}{\rho} \left( \frac{\partial }{\partial \rho} \left( \rho v_\phi \right) - \frac{\partial v_\rho}{\partial \phi} \right) \bm{\hat{z}}, \\
&= \frac{1}{r \sin(\theta)} \left[ \frac{\partial }{\partial \theta} \left(v_\phi \sin(\theta) \right) - \frac{\partial \phi}{\partial v_\theta} \right] \bm{\hat{r}} + \frac{1}{r} \left[ \frac{1}{\sin(\theta)} \frac{\partial v_r}{\partial \phi} - \frac{\partial }{\partial r}\left(r v_\phi\right) \right] \bm{\hat{\theta}} + \frac{1}{r} \left[ \frac{\partial }{\partial r}\left(r v_\phi\right) - \frac{\partial v_r}{\partial \theta} \right] \bm{\hat{\phi}}
\end{align*}
```

**Laplacian**:

```{math}
:label: defLaplacian2
\begin{align*}
\nabla^2 f &= \bm{\nabla} \cdot \left(\bm{\nabla} f \right) = \frac{\partial^2 f}{\partial x^2} + \frac{\partial^2 f}{\partial y^2} + \frac{\partial^2 f}{\partial z^2}, \\
&= \frac{1}{\rho} \frac{\partial }{\partial \rho} \left( \rho \frac{\partial f}{\partial \rho} \right) + \frac{1}{\rho^2} \frac{\partial^2 f}{\partial \phi^2} + \frac{\partial^2 f}{\partial z^2}, \\
&= \frac{1}{r^2} \frac{\partial }{\partial r} \left( r^2 \frac{\partial f}{\partial r} \right) + \frac{1}{r^2 \sin(\theta)} \frac{\partial }{\partial \theta} \left(\sin(\theta) \frac{\partial f}{\partial \theta}\right) + \frac{1}{r^2 \sin^2(\theta)} \frac{\partial^2 f}{\partial \phi^2}.
\end{align*}
```

