## Testing look-elsewhere effect by creating 2d chi-square random fields with a Gaussian Process

by Kyle Cranmer, Dec 7, 2015

The correction for 2d look-elsewhere effect presented in
*Estimating the significance of a signal in a multi-dimensional search* by  Ofer Vitells and Eilam Gross http://arxiv.org/pdf/1105.4355v1.pdf

is based on the fact that the test statistic

\begin{equation}
q(\nu_1, \nu_2) = -2 \log \frac{ \max_{\theta} L(\mu=0, \nu_1, \nu_2, \theta)}{ \max_{\mu, \theta} L(\mu, \nu_1, \nu_2, \theta)}
\end{equation}

is a chi-square random field (with 1 degree of freedom). That means that, for any point in $\nu_1, \nu_2$, the quantity $q(\nu_1, \nu_2)$ would have a chi-square distribution if you repeated the experiment many times.

That is what you expect if you have a background model $p_b(x|\theta)$ and you look for a signal on top of it with signal strength $\mu$. Creating that scan is somewhat time consuming, so here we make realizations of a chi-square random field by using a Gaussian Process.
The main trick we will use is that a chi-square distribution for one degree of freedom is the same as the distribution of $x^2$ if $x$ is normally distributed. As you might have guessed, a Gaussian Process (GP) is like a chi-square random field, but it is Gaussian-distributed at each point.

Note, the distributions are not independent at each point, there is some covaraince. So if the $q(\nu_1, \nu_2)$ is high at one point, you can expect it to be high near by. We can control this behavior via the GP's kernel.

For more on the theory of Gaussian Processes, the best resource is available for free online: [Rasmussen & Williams (2006)](http://www.gaussianprocess.org/gpml/). We will [`george`](http://dan.iel.fm/george/current/) -- a nice python package for Gaussian Processes (GP).

```python
%pylab inline --no-import-all
```

    Populating the interactive namespace from numpy and matplotlib

The main trick we will use is that a chi-square distribution for one degree of freedom is the same as the distribution of $x^2$ if $x$ is normally distributed. Here's a quick demonstration of that:

```python
from scipy.stats import chi2, norm
chi2_array = chi2.rvs(1, size=10000)
norm_array = norm.rvs(size=10000)
_ = plt.hist(chi2_array, bins=100, alpha=.5, label='chi-square')
_ = plt.hist(norm_array**2, bins=100, alpha=.5, color='r', label='x^2')
plt.yscale('log', nonposy='clip')
plt.legend(('chi-square', 'x^2'))
#plt.semilogy()
```

### Ok, now to the Gaussian processes.

```python
import george
from george.kernels import ExpSquaredKernel
```

```python
length_scale_of_correaltion=0.1
kernel = ExpSquaredKernel(length_scale_of_correaltion, ndim=2)
```

```python
# Create the Gaussian process
# gp = george.GP(kernel)
gp = george.GP(kernel, solver=george.HODLRSolver) #faster
```

```python
n_scan_points=50
aspect_ratio =  10. # make excesses look like stripes
x_scan = np.arange(0,aspect_ratio,aspect_ratio/n_scan_points)
y_scan = np.arange(0,1,1./n_scan_points)
xx, yy = np.meshgrid(x_scan, y_scan)
```

```python
# reformat the independent coordinates where we evaluate the GP
indep = np.vstack((np.hstack(xx),np.hstack(yy))).T
```

```python
# illustration of what is being done here
np.vstack([[1,2],[3,4]]).T
```

    array([[1, 3],
           [2, 4]])

```python
# slow part: pre-compute internal stuff for the GP
gp.compute(indep)
```

```python
# evaluate one realization of the GP
z = gp.sample(indep)
```

```python
# reformat output for plotting
zz = z.reshape((n_scan_points,n_scan_points))
```

```python
# plot the chi-square random field
plt.imshow(zz**2, cmap='gray')
plt.colorbar()
```

Now lets histogram the values of the random field.
Don't get confused here... if you pick a single point and histogram the value of over many instances, you expect a Gaussian. However, for a single instance, you don't expect the histogram for the value of the field to be Gaussian (because of the correlations). Thought experiments: if you make `length_scale_of_correaltion` very small, then each point is essentially independent and you do expect to see a Gaussian; however, if `length_scale_of_correaltion` is very large then you expect the field to be nearly constant and the histogram below would be a delta function.

```python
# plot the gaussian distributed x and chi-square distributed x**2
plt.subplot(1,2,1)
count, edges, patches = plt.hist(np.hstack(zz), bins=100)
plt.xlabel('z')
plt.subplot(1,2,2)
count, edges, patches = plt.hist(np.hstack(zz)**2, bins=100)
plt.xlabel('q=z**2')
plt.yscale('log', nonposy='clip')
```

## Ok, now let's repeat that several times and test lee2d

```python
from lee2d import *

```

```python
from scipy.ndimage import grey_closing, binary_closing

def fill_holes(array):
    zero_array = array==0.
    temp = grey_closing(array, size=2)*zero_array
    print np.sum(temp)
    return temp+array

```

Generate 25 realizations of the GP, calculate the Euler characteristic for two thresholds, and use the mean of those Euler characteristics to estimate $N_1$ and $N_2$

```python
n_samples = 25
z_array = gp.sample(indep,n_samples)

q_max = np.zeros(n_samples)
phis = np.zeros((n_samples,2))

u1,u2 = 0.5, 1.

n_plots = 10
plt.figure(figsize=(9,n_plots*3))
for scan_no, z in enumerate(z_array):

    scan = z.reshape((n_scan_points,n_scan_points))**2

    q_max[scan_no] = np.max(scan)

    # set a point to 0 to simulate misc failure
    scan[n_scan_points/2,n_scan_points/2] = 0.
    scan[n_scan_points/4,n_scan_points/2] = 0.
    scan[n_scan_points/2,n_scan_points/4] = 0.

    newscan = fill_holes(scan)
    diffscan = scan-newscan

    #get excursion sets above those two levels
    exc1 = (scan>u1) + 0. #add 0. to convert from bool to double
    exc2 = (scan>u2) + 0.
    #print '\nu1,u2 = ', u1, u2

    #print 'diff = ', np.sum(exc1), np.sum(exc2)

    if scan_no < n_plots:
        aspect = 1.
        plt.subplot(n_plots,3,3*scan_no+1)
        aspect = 1.*scan.shape[0]/scan.shape[1]
        plt.imshow(scan.T, cmap='gray', aspect=aspect)
        plt.subplot(n_plots,3,3*scan_no+2)
        #plt.imshow(exc1.T, cmap='gray', aspect=aspect, interpolation='none')
        plt.imshow(newscan.T, cmap='gray', aspect=aspect, interpolation='none')
        plt.subplot(n_plots,3,3*scan_no+3)
        plt.imshow(diffscan.T, cmap='gray', aspect=aspect, interpolation='none')

    phi1 = calculate_euler_characteristic(exc1)
    phi2 = calculate_euler_characteristic(exc2)
    #print 'phi1, phi2 = ', phi1, phi2
    #print 'q_max = ', np.max(scan)

    phis[scan_no] = [phi1, phi2]

plt.savefig('chi-square-random-fields.png')
```

```python
exp_phi_1, exp_phi_2 = np.mean(phis[:,0]), np.mean(phis[:,1])
exp_phi_1, exp_phi_2
```

    (14.32, 13.4)

```python
n1, n2 = get_coefficients(u1=u1, u2=u2, exp_phi_1=exp_phi_1, exp_phi_2=exp_phi_2)
print n1, n2
```

    8.60199674222 12.9677117014

With estimates of $N_1$ and $N_2$ predict the global p-value vs. u

```python
u = np.linspace(5,25,100)
global_p = global_pvalue(u,n1,n2)
```

### Generate 5000 instances of the Gaussian Process, find maximum local significance for each, and check the prediction for the LEE-corrected global p-value

```python
n_samples = 5000
z_array = gp.sample(indep,n_samples)

q_max = np.zeros(n_samples)

for scan_no, z in enumerate(z_array):
    scan = z.reshape((n_scan_points,n_scan_points))**2
    q_max[scan_no] = np.max(scan)
```

```python
bins, edges, patches = plt.hist(q_max, bins=30)
icdf = 1.-np.cumsum(bins/n_samples)
icdf = np.hstack((1.,icdf))
icdf_error = np.sqrt(np.cumsum(bins))/n_samples
icdf_error = np.hstack((0.,icdf_error))
plt.xlabel('q_max')
plt.ylabel('counts / bin')
```

```python
# plot the p-value
plt.subplot(121)
plt.plot(edges,icdf, c='r')
plt.errorbar(edges,icdf,yerr=icdf_error)
plt.plot(u, global_p)
plt.xlabel('u')
plt.ylabel('P(q_max >u)')
plt.xlim(0,25)
plt.subplot(122)
plt.plot(edges,icdf, c='r', label='toys')
plt.errorbar(edges,icdf,yerr=icdf_error)
plt.plot(u, global_p, label='prediction')
plt.xlabel('u')
plt.legend(('toys', 'prediction'))
#plt.ylabel('P(q>u)')
plt.ylim(1E-3,10)
plt.xlim(0,25)
plt.semilogy()
```

```python

```

```python

```


# Multi-dimensional Particle-in-a-Box

## 🥅 Learning Objectives
- Hamiltonian for a two-dimensional particle-in-a-box
- Hamiltonian for a three-dimensional particle-in-a-box
- Hamiltonian for a 3-dimensional spherical box
- Separation of variables
- Solutions for the 2- and 3- dimensional particle-in-a-box (rectangular)
- Solutions for the 3-dimensional particle in a box (spherical)
- Expectation values

## The 2-Dimensional Particle-in-a-Box

We have treated the particle in a one-dimensional box, where the (time-independent) Schrödinger equation was:

$$
\left(-\frac{\hbar^2}{2m} \frac{d^2}{dx^2} + V(x) \right)\psi_n(x) = E_n \psi_n(x)
$$

where

$$
V(x) =
\begin{cases}
    +\infty & x\leq 0\\
    0       & 0\lt x \lt a\\
    +\infty & a \leq x
\end{cases}
$$

However, electrons really move in three dimensions. However, just as sometimes electrons are (essentially) confined to one dimension, sometimes they are effectively confined to two dimensions. If the confinement is to a rectangle with side-widths $a_x$ and $a_y$, then the Schrödinger equation is:

$$
\left(-\frac{\hbar^2}{2m} \frac{d^2}{dx^2} -\frac{\hbar^2}{2m} \frac{d^2}{dy^2} + V(x,y) \right)\psi_{n_x,n_y}(x,y) = E_{n_x,n_y} \psi_{n_x,n_y}(x,y)
$$

where

$$
V(x,y) =
\begin{cases}
    +\infty & x\leq 0 \text{ or }y\leq 0 \\
    0       & 0\lt x \lt a_x \text{ and } 0 \lt y \lt a_y \\
    +\infty & a_x \leq x \text{ or } a_y \leq y
\end{cases}
$$

The first thing to notice is that there are now two quantum numbers, $n_x$ and $n_y$.
> The number of quantum numbers that are needed to label the state of a system is equal to its dimensionality.

The second thing to notice is that the Hamiltonian in this Schrödinger equation can be written as the sum of two Hamiltonians,

$$
\left[\left(-\frac{\hbar^2}{2m} \frac{d^2}{dx^2} + V_x(x) \right)
+\left(-\frac{\hbar^2}{2m} \frac{d^2}{dy^2} + V_y(y) \right) \right]\psi_{n_x,n_y}(x,y) = E_{n_x,n_y} \psi_{n_x,n_y}(x,y)
$$

where

$$
V_x(x) =
\begin{cases}
    +\infty & x\leq 0\\
    0       & 0\lt x \lt a_x\\
    +\infty & a_x \leq x
\end{cases} \\
V_y(y) =
\begin{cases}
    +\infty & y\leq 0\\
    0       & 0\lt y \lt a_y\\
    +\infty & a_y \leq y
\end{cases}
$$

By the same logic as we used for the 1-dimensional particle in a box, we can deduce that the ground-state wavefunction for an electron in a rectangular box is:

$$
\psi_{n_x n_y}(x,y) = \frac{2}{\sqrt{a_x a_y}} \sin\left(\tfrac{n_x \pi x}{a_x}\right) \sin\left(\tfrac{n_y \pi y}{a_y}\right) \qquad \qquad n_x=1,2,3,\ldots;n_y=1,2,3,\ldots
$$

The corresponding energy is thus:

$$
E_{n_x n_y} =  \frac{h^2}{8m}\left(\frac{n_x^2}{a_x^2}+\frac{n_y^2}{a_y^2}\right)\qquad \qquad n_x,n_y=1,2,3,\ldots
$$

## 📝 Exercise: Verify the above equation for the energy eigenvalues of a particle confined to a rectangular box.

## Separation of Variables
The preceding solution is a very special case of a general approach called separation of variables.
> Given a $D$-dimensional Hamiltonian that is a sum of independent terms,

$$
\hat{H}(x_1,x_2,\ldots,x_D) = \sum_{d=1}^D\hat{H}_d(x_d)
$$

where the solutions to the individual Schrödinger equations are known:

$$
\hat{H}_d \psi_{d;n_d}(x_d) = E_{d;n_d} \psi_{d;n_d}(x_d)
$$

the solution to the $D$-dimensional Schrödinger equation is

$$
\hat{H}(x_1,x_2,\ldots,x_D) \Psi_{n_1,n_2,\ldots,n_D}(x_1,x_2,\ldots,x_D) = E_{n_1,n_2,\ldots,n_D}\Psi_{n_1,n_2,\ldots,n_D}(x_1,x_2,\ldots,x_D)
$$

where the $D$-dimensional eigenfunctions are products of the Schrödinger equations of the individual terms

$$
\Psi_{n_1,n_2,\ldots,n_D}(x_1,x_2,\ldots,x_D) = \prod_{d=1}^D\psi_{d;n_d}(x_d)
$$

and the $D$-dimensional eigenvalues are sums of the eigenvalues of the individual terms,

$$
E_{n_1,n_2,\ldots,n_D} = \sum_{d=1}^D E_{d;n_d}
$$

This expression can be verified by direct substitution. Interpretatively, in a Hamiltonian with the form

$$
\hat{H}(x_1,x_2,\ldots,x_D) = \sum_{d=1}^D\hat{H}_d(x_d)
$$

the coordinates $x_1,x_2,\ldots,x_D$ are all independent, because there are no terms that couple them together in the Hamiltonian. This means that the probability of observing a particle with values $x_1,x_2,\ldots,x_D$ are all independent. Recall that when probabilities are independent, they are multiplied together. E.g., if the probability that your impoverished professor will be paid today is independent of the probability that will rain today, then

$$
p_{\text{paycheck + rain}} = p_{\text{paycheck}} p_{\text{rain}}
$$

Similarly, because $x_1,x_2,\ldots,x_D$ are all independent,

$$
p(x_1,x_2,\ldots,x_D) = p_1(x_1) p_2(x_2) \ldots p_D(x_D)
$$

Owing to the Born postulate, the probability distribution function for observing a particle at $x_1,x_2,\ldots,x_D$ is the wavefunction squared, so

$$
\left| \Psi_{n_1,n_2,\ldots,n_D}(x_1,x_2,\ldots,x_D)\right|^2 = \prod_{d=1}^D \left| \psi_{d;n_d}(x_d) \right|^2
$$

It is reassuring that the separation-of-independent-variables solution to the $D$-dimensional Schrödinger equation reproduces this intuitive conclusion.

#### 📝 Exercise: By direct substitution, verify that the above expressions for the eigenvalues and eigenvectors of a Hamiltonian-sum are correct.

#### 📝 Exercise: Write the Time-Dependent Schrödinger equation for one particle, in three dimensions, confined by the time-dependent potential $V(x,y,z,t)$.
[Answer](MultiDExercise1.md)

## Degenerate States
When two quantum states have the same energy, they are said to be degenerate. For example, for a square box, where $a_x = a_y = a$, the states with $n_x=1; n_y=2$ and $n_x=2;n_y=1$ are degenerate because:

$$
E_{1,2} =  \frac{h^2}{8ma^2}\left(1+4\right) = \frac{h^2}{8ma^2}\left(4+1\right) = E_{2,1}
$$

This symmetry reflects physical symmetry, whereby the $x$ and $y$ coordinates are equivalent. The state with energy $E=\frac{5h^2}{8ma^2}$ is said to be two-fold degenerate, or to have degeneracy of two.

For the particle in a square box, degeneracies of all levels exist. An example of a three-fold degeneracy is:

$$
E_{1,7} = E_{7,1} = E_{5,5} = \frac{50h^2}{8ma^2}
$$

and an example of a four-fold degeneracy is:

$$
E_{1,8} = E_{8,1} = E_{7,4} = E_{4,7} = \frac{65h^2}{8ma^2}
$$

It isn't trivial to show that degeneracies of all orders are possible (it's tied up in the theory of [Diophantine equations](https://en.wikipedia.org/wiki/Diophantine_equation)), but perhaps it becomes plausible by giving an example with an eight-fold degeneracy:

$$
E_{8,49} = E_{49,8} = E_{16,47} = E_{47,16} = E_{23,44} = E_{44,23} = E_{28,41} = E_{41,28}  = \frac{2465 h^2}{8ma^2}
$$

Notice that all of these degeneracies are removed if the symmetry of the box is broken. For example, if a slight change of the box changes it from square to rectangulary, $a_x \rightarrow a_x + \delta x$, then the aforementioned states have different energies. This doesn't mean, however, that rectangular boxes do not have degeneracies. If $\tfrac{a_x}{a_y}$ is a rational number, $\tfrac{p}{q}$, then there will be an *accidental* degeneracies when $n_x$ is divisible by $p$ and $n_y$ is divisible by $q$. For example, if $a_x = 2a$ and $a_y = 3a$ (so $p=2$ and $q=3$), there is a degeneracy associated with

$$
E_{4,3} =  \frac{h^2}{8m}\left(\frac{4^2}{(2a)^2}+\frac{3^2}{(3a)^2}\right)
=  \frac{h^2}{8m}\left(\frac{2^2}{(2a)^2}+\frac{6^2}{(3a)^2}\right) = \frac{5h^2}{8ma^2}= E_{2,6}
$$

This is called an *accidental* degeneracy because it is not related to a symmetry of the system, like the $x \sim y$ symmetry that induces the degeneracy in the case of particles in a square box.

## Electrons in a 3-dimensional box (cuboid)

Suppose that particles are confined to a [cuboid](https://en.wikipedia.org/wiki/Cuboid) (or rectangular prism) with side-lengths $a_x$, $a_y$, and $a_z$. Then the Schrödinger equation is:

$$
\left[-\frac{\hbar^2}{2m}\left( \frac{d^2}{dx^2} + \frac{d^2}{dy^2} + \frac{d^2}{dz^2} \right) + V(x,y,z) \right]\psi_{n_x,n_y,n_z}(x,y,z) = E_{n_x,n_y,n_z} \psi_{n_x,n_y,n_z}(x,y,z)
$$

where

$$
V(x,y,z) =
\begin{cases}
    +\infty & x\leq 0 \text{ or }y\leq 0 \text{ or }z\leq 0 \\
    0       & 0\lt x \lt a_x \text{ and } 0 \lt y \lt a_y  \text{ and } 0 \lt z \lt a_z \\
    +\infty & a_x \leq x \text{ or } a_y \leq y \text{ or } a_z \leq z
\end{cases}
$$

There are three quantum numbers because the system is three-dimensional.

The three-dimensional second derivative is called the Laplacian, and is denoted

$$
\nabla^2 =  \frac{d^2}{dx^2} + \frac{d^2}{dy^2} + \frac{d^2}{dz^2} = \nabla \cdot \nabla
$$

where

$$
\nabla = \left[ \frac{d}{dx}, \frac{d}{dy}, \frac{d}{dz} \right]^T
$$

is the operator that defines the gradient vector. The 3-dimensional momentum operator is

$$
\hat{\mathbf{p}} = -i \hbar \nabla
$$

which explains why the kinetic energy is given by

$$
\hat{T} = \frac{\hat{\mathbf{p}} \cdot \hat{\mathbf{p}}}{2m} = -\frac{\hbar^2}{2m} \nabla^2
$$

As with the 2-dimensional particle-in-a-rectangle, the 3-dimensional particle-in-a-cuboid can be solved by separation of variables. Rewriting the Schrödinger equation as:

$$
\left[\left(-\frac{\hbar^2}{2m} \frac{d^2}{dx^2} + V_x(x) \right)
+\left(-\frac{\hbar^2}{2m} \frac{d^2}{dy^2} + V_y(y) \right)
+\left(-\frac{\hbar^2}{2m} \frac{d^2}{dz^2} + V_z(z) \right) \right]\psi_{n_x,n_y,n_z}(x,y,z) = E_{n_x,n_y,n_z} \psi_{n_x,n_y,n_z}(x,y,z)
$$

where

$$
V_x(x) =
\begin{cases}
    +\infty & x\leq 0\\
    0       & 0\lt x \lt a_x\\
    +\infty & a_x \leq x
\end{cases} \\
V_y(y) =
\begin{cases}
    +\infty & y\leq 0\\
    0       & 0\lt y \lt a_y\\
    +\infty & a_y \leq y
\end{cases} \\
V_z(z) =
\begin{cases}
    +\infty & z\leq 0\\
    0       & 0\lt z \lt a_z\\
    +\infty & a_z \leq z
\end{cases}
$$

By the same logic as we used for the 1-dimensional particle in a box, we can deduce that the ground-state wavefunction for an electron in a cuboid is:

$$
\psi_{n_x n_y n_z}(x,y,z) = \frac{2\sqrt{2}}{\sqrt{a_x a_y a_z}} \
\sin\left(\tfrac{n_x \pi x}{a_x}\right) \sin\left(\tfrac{n_y \pi y}{a_y}\right)\sin\left(\tfrac{n_z \pi z}{a_z}\right) \qquad \qquad n_x=1,2,3,\ldots;n_y=1,2,3,\ldots;n_z=1,2,3,\ldots
$$

The corresponding energy is thus:

$$
E_{n_x n_y n_z} =  \frac{h^2}{8m}\left(\frac{n_x^2}{a_x^2}+\frac{n_y^2}{a_y^2}+\frac{n_z^2}{a_z^2}\right)\qquad \qquad n_x,n_y,n_z=1,2,3,\ldots
$$

As before, especially when there is symmetry, there are many degenerate states. For example, for a particle-in-a-cube, where $a_x = a_y = a_z = a$, the first excited state is three-fold degenerate since:

$$
E_{2,1,1} = E_{1,2,1} = E_{1,1,2} = \frac{6h^2}{8ma^2}
$$

There are other states of even higher degeneracy. For example, there is a twelve-fold degenerate state:

$$
E_{5,8,15} = E_{5,15,8} = E_{8,5,15} = E_{8,15,5} = E_{15,5,8} = E_{15,8,5} = E_{3,4,17} = E_{3,17,4} = E_{4,3,17} = E_{4,17,3} = E_{17,3,4} = E_{17,4,3} = \frac{314 h^2}{8ma^2}
$$

## 📝 Exercise: Verify the expressions for the eigenvalues and eigenvectors of a particle in a cuboid.

## 📝 Exercise: Construct an accidentally degenerate state for the particle-in-a-cuboid.
(Hint: this is a lot easier than you may think.)

## Particle-in-a-circle
### The Schrödinger equation for a particle confined to a circular disk.
.jpg?raw=true "The states of particle confined by a ring of atoms (a quantum corral) is similar to a particle-in-acircle. Image licensed CC-SA by Julian Voss-Andreae")

What happens if instead of being confined to a rectangle or a cuboid, the electrons were confined to some other shape? For example, it is not uncommon to have electrons confined in a circular disk ([quantum corral](https://en.wikipedia.org/wiki/Quantum_mirage)) or a sphere ([quantum dot](https://en.wikipedia.org/wiki/Quantum_dot)). It is relatively easy to write the Hamiltonian in these cases, but less easy to solve it because Cartesian (i.e., $x,y,z$) coordinates are less natural for these geometries.

The Schrödinger equation for a particle confined to a circular disk of radius $a$ is:

$$
\left(-\frac{\hbar^2}{2m} \nabla^2 + V(x,y) \right)\psi(x,y) = E \psi(x,y)
$$

where

$$
V(x,y) =
\begin{cases}
    0 & \sqrt{x^2 + y^2} \lt a\\
    +\infty & a \leq \sqrt{x^2 + y^2}
\end{cases}
$$

However, it is more useful to write this in polar coordinates (i.e., $r,\theta$):

$$
\begin{align}
x &= r \cos \theta \\
y &= r \sin \theta \\
\\
r &= \sqrt{x^2 + y^2} \\
\theta &= \arctan{\tfrac{y}{x}}
\end{align}
$$

because the potential depends only on the distance from the center of the system,

$$
\left(-\frac{\hbar^2}{2m} \nabla^2 + V(r) \right)\psi(r,\theta) = E \psi(r,\theta)
$$

where

$$
V(r) =
\begin{cases}
    0 & r \lt a\\
    +\infty & a \leq r
\end{cases}
$$

### The Schrödinger Equation in Polar Coordinates
In order to solve this Schrödinger equation, we need to rewrite the Laplacian, $\nabla^2 = \frac{d^2}{dx^2} + \frac{d^2}{dy^2}$ in polar coordinates. Deriving the Laplacian in alternative coordinate systems is a standard (and tedious) exercise that you hopefully saw in your calculus class. (If not, cf. [wikipedia](https://en.wikipedia.org/wiki/Laplace_operator) or this [meticulous derivation](https://www.math.ucdavis.edu/~saito/courses/21C.w11/polar-lap.pdf).) The result is that:

$$
\nabla^2 = \frac{d^2}{dr^2} + \frac{1}{r} \frac{d}{dr} + \frac{1}{r^2}\frac{d^2}{d\theta^2}
$$

The resulting Schrödinger equation is,

$$
\left[-\frac{\hbar^2}{2m} \left(\frac{d^2}{dr^2} + \frac{1}{r} \frac{d}{dr} + \frac{1}{r^2}\frac{d^2}{d\theta^2} \right)+ V(r)  \right] \psi(r,\theta) = E \psi(r,\theta)
$$

This looks like it might be amenable to solution by separation of variables insofar as the potential doesn't compute the radial and angular positions of the particles, and the kinetic energy doesn't couple the particles angular and radial momenta (i.e., the derivatives). So we propose the solution $\psi(r,\theta) = R(r) \Theta(\theta)$. Substituting this into the Schrödinger equation, we obtain:

$$
\begin{align}
\left[-\frac{\hbar^2}{2m} \left(\frac{d^2}{dr^2} + \frac{1}{r} \frac{d}{dr} + \frac{1}{r^2}\frac{d^2}{d\theta^2} \right)+ V(r)  \right] R(r) \Theta(\theta) &= E R(r) \Theta(\theta) \\
\left[-\Theta(\theta)\frac{\hbar^2}{2m} \left(\frac{d^2 R(r)}{dr^2} + \frac{1}{r} \frac{d R(r)}{dr} \right) -\frac{\hbar^2}{2m} \frac{R(r)}{r^2}\left(\frac{d^2 \Theta(\theta)}{d \theta^2} \right) + V(r) R(r) \Theta(\theta)  \right] &= E R(r)\Theta(\theta)
\end{align}
$$

Dividing both sides by $R(r) \Theta(\theta)$ and multiplying both sides by $r^2$ we obtain:

$$
E r^2 +\frac{\hbar^2}{2m}\frac{r^2}{R(r)} \left(\frac{d^2 R(r)}{dr^2} + \frac{1}{r} \frac{d R(r)}{dr} \right) - r^2 V(r)=-\frac{\hbar^2}{2m} \frac{1}{\Theta(\theta)}\left(\frac{d^2 \Theta(\theta)}{d \theta^2} \right)
$$

The right-hand-side depends only on $r$ and the left-hand-side depends only on $\theta$; this can only be true for all $r$ and all $\theta$ if both sides are equal to the same constant. This problem can therefore be solved by separation of variables, though it is a slightly different form from the one we considered previously.

### The Angular Schrödinger equation in Polar Coordinates
To find the solution, we first solve the set the left-hand-side equal to a constant, which gives a 1-dimensional Schrödinger equations for the angular motion of the particle around the circle,

$$
-\frac{\hbar^2}{2m} \frac{d^2 \Theta_l(\theta)}{d \theta^2} = E_{\theta;l} \Theta_l(\theta)
$$

This equation is identical to the particle-in-a-box, and has (unnormalized) solutions

$$
\Theta_l(\theta) = e^{i l \theta} \qquad \qquad l = 0, \pm 1, \pm 2, \ldots
$$

where $l$ must be an integer because otherwise the fact the periodicity of the wavefunction (i.e., that $\Theta_l(\theta) = \Theta_l(\theta + 2 k \pi)$ for any integer $k$) is not achieved. Using the expression for $\Theta_l(\theta)$, the angular kinetic energy of the particle in a circle is seen to be:

$$
E_{\theta,l} = \tfrac{\hbar^2 l^2}{2m}
$$

### The Radial Schrödinger equation in Polar Coordinates
Inserting the results for the angular wavefunction into the Schrödinger equation, we obtain

$$
E r^2 +\frac{\hbar^2}{2m}\frac{r^2}{R(r)} \left(\frac{d^2 R(r)}{dr^2} + \frac{1}{r} \frac{d R(r)}{dr} \right) - r^2 V(r)=-\frac{\hbar^2}{2m} \frac{1}{\Theta_l(\theta)}\left(\frac{d^2 \Theta_l(\theta)}{d \theta^2} \right) = \frac{\hbar^2 l^2}{2m}
$$

which can be rearranged into the radial Schrödinger equation,

$$
-\frac{\hbar^2}{2m} \left( \frac{d^2}{dr^2} + \frac{1}{r} \frac{d}{dr} - \frac{l^2}{r^2} \right)R_{n,l}(r) + V(r) R_{n,l}(r) = E_{n,l} R_{n,l}(r)
$$

Notice that the radial eigenfunctions, $R_{n,l}(r)$, and the energy eigenvalues, $E_{n,l}$, depend on the angular motion of the particle, as quantized by $l$. The term $\frac{\hbar^2 l^2}{2mr^2}$ is exactly the centrifugal potential, indicating that it takes energy to hold a rotating particle in an orbit with radius $r$, and that the potential energy that is required grows with $r^{-2}$. Notice also that no assumptions have been made about the nature of the circular potential, $V(r)$. The preceding analysis holds for *any* circular-symmetric potential.

### The Radial Schrödinger Equation for a Particle Confined to a Circular Disk
For the circular disk, where

$$
V(r) =
\begin{cases}
    0 & r \lt a\\
    +\infty & a \leq r
\end{cases}
$$

it is somewhat more convenient to rewrite the radial Schrödinger equation as a [homogeneous linear differential equation](https://en.wikipedia.org/wiki/Homogeneous_differential_equation)

$$
-\frac{\hbar^2}{2m} \left(r^2 \frac{d^2 R_{n,l}(r)}{dr^2} + r \frac{d R_{n,l}(r)}{dr} + \left[\left(\frac{2m E_{n,l}}{\hbar^2} \right) r^2 - l^2\right]R_{n,l}(r) \right) + r^2 V(r) R_{n,l}(r) = 0
$$

Using the specific form of the equation, we have that, for $0 \lt r \lt a$,

$$
-\frac{\hbar^2}{2m} \left(r^2 \frac{d^2 R_{n,l}(r)}{dr^2} + r \frac{d R_{n,l}(r)}{dr} + \left[\left(\frac{2m E_{n,l}}{\hbar^2} \right) r^2 - l^2\right]R_{n,l}(r) \right) = 0
$$

While this equation can be solved by the usual methods, that is [beyond the scope of this course](https://opencommons.uconn.edu/cgi/viewcontent.cgi?article=1013&context=chem_educ). However, we recognize that this equation is strongly resembles [Bessel's differential equation](https://en.wikipedia.org/wiki/Bessel_function),

$$
x^2 \frac{d^2 f}{dx^2} + x \frac{df}{dx} + \left(x^2 - \alpha^2 \right) f(x) = 0
$$

The solutions to Bessel's equation are called the *Bessel functions of the first kind* and denoted, $J_{\alpha}(r)$. However, the radial wavefunction must vanish at the edge of the disk, $R_{n,l}(a) = 0$, and the Bessel functions generally do not satisfy this requirement. Recall that the boundary condition in the 1-dimensional particle in a box was satisfied by moving from the generic solution, $\psi(x) \propto \sin(x)$ to the scaled solution, $\psi(x) \propto \sin(k x)$, where $k=\tfrac{2 \pi}{a}$ was chosen to satisfy the boundary condition. Similarly, we write the solutions as $R_{n,l}(r) \propto J_l(kr)$. Substituting this form into the Schrödinger equation and using the fact that:

$$
(kr)^n \frac{d^n}{d(kr)^n} = r^n \frac{d^n}{dr^n} \qquad \qquad n=1,2,\ldots
$$

we have

$$
-\frac{\hbar^2}{2m} \left((kr)^2 \frac{d^2 J_{l}(kr)}{d(kr)^2} + (kr) \frac{d J_{l}(kr)}{d(kr)} + \left[\left(\frac{2m E_{n,l}}{k^2 \hbar^2} \right) (kr)^2 - l^2\right]J_{l}(kr) \right) = 0
$$

Referring back to the Bessel equation, it is clear that this equation is satisfied when

$$
\frac{2m E_{n,l}}{k^2 \hbar^2} = 1
$$

or, equivalently,

$$
E_{n,l} = \frac{\hbar^2 k^2}{2m}
$$

where $k$ is chosen so that $J_l(ka) = 0$. If we label the zeros of the Bessel functions,

$$
J_l(x_{n,l}) = 0 \qquad \qquad n=1,2,3,\ldots \\
x_{1,l} \lt x_{2,l} \lt x_{3,l} \lt \cdots
$$

then

$$
k_{n,l} = \frac{x_{n,l}}{a}
$$

and the energies of the particle-in-a-disk are

$$
E_{n,l} = \frac{\hbar^2 x_{n,l}^2}{2ma^2} = \frac{h^2 x_{n,l}^2}{8 m \pi^2 a^2}
$$

and the eigenfunctions of the particle-in-a-disk are:

$$
\psi_{n,l}(r,\theta) \propto J_{l}\left(\frac{x_{n,l}r}{a} \right) e^{i l \theta}
$$

### Eigenvalues and Eigenfunctions for a Particle Confined to a Circular Disk

The energies of a particle confined to a circular disk of radius $a$ are:

$$
E_{n,l} = \frac{\hbar^2 x_{n,l}^2}{2ma^2} = \frac{h^2 x_{n,l}^2}{8 m \pi^2 a^2} \qquad \qquad n=1,2,\ldots; \quad l=0,\pm 1,\pm 2, \ldots
$$

and its eigenfunctions are:

$$
\psi_{n,l}(r,\theta) \propto J_{l}\left(\frac{x_{n,l}r}{a} \right) e^{i l \theta}
$$

where $x_{n,l}$ are the zeros of the Bessel function, $J_l(x_{n,l}) = 0$. The first zero is $x_{1,0} = 2.4048$. These solutions are exactly the resonant energies and modes that are associated with the vibration of a circular drum whose membrane has uniform thickness/density.

You can find elegant video animations of the eigenvectors of the particle-in-a-circle at the following links:
- [Interactive Demonstration of the States of a Particle-in-a-Circular-Disk](https://demonstrations.wolfram.com/ParticleInAnInfiniteCircularWell/)
- [Movie animation of the quantum states of a particle-in-a-circular-disk](https://www.reddit.com/r/dataisbeautiful/comments/mfx5og/first_70_states_of_a_particle_trapped_in_a/?utm_source=share&utm_medium=web2x&context=3)

A subtle result, [originally proposed by Bourget](https://en.wikipedia.org/wiki/Bessel_function#Bourget's_hypothesis), is that no two Bessel functions ever have the same zeros, which means that the values of $\{x_{n,l} \}$ are all distinct. A corollary of this is that eigenvalues of the particle confined to a circular disk are either nondegenerate ($l=0$) or doubly degenerate ($|l| /ge 1$). There are no accidental degeneracies for a particle in a circular disk.

The energies of an electron confined to a circular disk with radius $a$ Bohr are:

$$
E_{n,l} = \tfrac{x_{n,l}^2}{2a^2}
$$

The following code block computes these energies.

```python
from scipy import constants
from scipy import special
import ipywidgets as widgets
import mpmath
```

```python
# Define a function for the energy (in a.u.) of a particle in a circular disk
# with length a, principle quantum number n, and angular quantum number l
# The length is input in Bohr (atomic units).
def compute_energy_disk(n, l, a):
    "Compute 1-dimensional particle-in-a-spherical-ball energy."
    #Compute the first n zeros of the Bessel function
    zeros = special.jn_zeros(l,n)
    #Compute the energy from the n-th zero.
    return  (zeros[-1])**2/ (2 * a**2)

#This next bit of code just prints out the energy in atomic units
def print_energy_disk(a, n, l):
    print(f'The energy of an electron confined to a disk with radius {a:.2f} a.u.,'
       f' principle quantum number {n}, and angular quantum number {l}'
       f' is {compute_energy_disk(n, l, a):.3f} a.u..')

#Principle quantum number slider:
n = 1

#Angular quantum number slider:
l = 0

#Box length slider:
a = 1

print_energy_disk(a, n, l)
```

    The energy of an electron confined to a disk with radius 1.00 a.u., principle quantum number 1, and angular quantum number 0 is 2.892 a.u..

## Particle-in-a-Spherical Ball

### The Schrödinger equation for a particle confined to a spherical ball

The final model we will consider for now is a particle confined to a spherical ball with radius $a$,

$$
\left(-\frac{\hbar^2}{2m} \nabla^2 + V(x,y,z) \right)\psi(x,y,z) = E \psi(x,y,z)
$$

where

$$
V(x,y,z) =
\begin{cases}
    0 & \sqrt{x^2 + y^2 + z^2} \lt a\\
    +\infty & a \leq \sqrt{x^2 + y^2 + z^2}
\end{cases}
$$

However, it is more useful to write this in spherical polar coordinates (i.e., $r,\theta, \phi$):

$$
\begin{align}
x &= r \sin \theta \cos \phi\\
y &= r \sin \theta \sin \phi\\
z &= r cos \theta \\
\\
r &= \sqrt{x^2 + y^2 + z^2} \\
\theta &= \arccos{\tfrac{z}{r}} \\
\phi &= \arctan{\tfrac{y}{x}}
\end{align}
$$

because the potential depends only on the distance from the center of the system,

$$
\left(-\frac{\hbar^2}{2m} \nabla^2 + V(r) \right)\psi(r,\theta, \phi) = E \psi(r,\theta, \phi)
$$

where

$$
V(r) =
\begin{cases}
    0 & r \lt a\\
    +\infty & a \leq r
\end{cases}
$$

### The Schrödinger Equation in Spherical Coordinates
In order to solve the Schrödinger equation for a particle in a spherical ball, we need to rewrite the Laplacian, $\nabla^2 = \frac{d^2}{dx^2} + \frac{d^2}{dy^2} + \frac{d^2}{dz^2}$ in polar coordinates. A meticulous derivation of the [Laplacian](https://en.wikipedia.org/wiki/Laplace_operator) and its [eigenfunctions](http://galileo.phys.virginia.edu/classes/252/Classical_Waves/Classical_Waves.html) The result is that:

$$
\nabla^2 = \frac{1}{r^2}\frac{d}{dr}r^2\frac{d}{dr} + \frac{1}{r^2 \sin \theta}\frac{d}{d\theta}\sin\theta\frac{d}{d\theta} + \frac{1}{r^2 \sin^2 \theta} \frac{d^2}{d\phi^2}
$$

which can be rewritten in a more familiar form as:

$$
\nabla^2 = \frac{d^2}{dr^2}+ \frac{2}{r}\frac{d}{dr} + \frac{1}{r^2}\left[\frac{1}{\sin \theta}\frac{d}{d\theta}\sin\theta\frac{d}{d\theta} + \frac{1}{\sin^2 \theta} \frac{d^2}{d\phi^2}\right]
$$

Inserting this into the Schrödinger equation for a particle confined to a spherical potential, $V(r)$, one has:

$$
\left({}  -\frac{\hbar^2}{2m} \left( \frac{d^2}{dr^2}
+ \frac{2}{r} \frac{d}{dr}\right)
      - \frac{\hbar^2}{2mr^2}\left[\frac{1}{\sin \theta}\frac{d}{d\theta}\sin\theta\frac{d}{d\theta}
+ \frac{1}{\sin^2 \theta} \frac{d^2}{d\phi^2}\right] \\
      + V(r) \right)\psi_{n,l,m_l}(r,\theta,\phi)
= E_{n,l,m_l}\psi_{n,l,m_l}(r,\theta,\phi)
$$

The solutions of the Schrödinger equation are characterized by three quantum numbers because this equation is 3-dimensional.

Recall that the classical equation for the kinetic energy of a set of points rotating around the origin, in spherical coordinates, is:

$$
T = \sum_{i=1}^{N_{\text{particles}}} \frac{p_{r;i}^2}{2m_i} + \frac{\mathbf{L}_i \cdot \mathbf{L}_i}{2m_i r_i^2}
$$

where $p_{r,i}$ and $\mathbf{L}_i$ are the radial and [angular momenta](https://en.wikipedia.org/wiki/Angular_momentum#In_Hamiltonian_formalism) of the $i^{\text{th}}$ particle, respectively. It's apparent, then, that the quantum-mechanical operator for the square of the angular momentum is:

$$
\hat{L}^2 = - \hbar^2 \left[\frac{1}{\sin \theta}\frac{d}{d\theta}\sin\theta\frac{d}{d\theta}
+ \frac{1}{\sin^2 \theta} \frac{d^2}{d\phi^2}\right]
$$

The Schrödinger equation for a spherically-symmetric system is thus,

$$
\left(-\frac{\hbar^2}{2m} \left( \frac{d^2}{dr^2}
+ \frac{2}{r} \frac{d}{dr}\right)
      + \frac{\hat{L}^2}{2mr^2} + V(r) \right)
      \psi_{n,l,m_l}(r,\theta,\phi)
= E_{n,l,m_l}\psi_{n,l,m_l}(r,\theta,\phi)
$$

### The Angular Wavefunction in Spherical Coordinates

The Schrödinger equation for a spherically-symmetric system can be solved by separation of variables. If one compares to the result in polar coordinates, it is already clear that the angular wavefunction has the form $\Theta(\theta,\phi) = P(\theta)e^{im_l\phi}$. From this starting point we could deduce the eigenfunctions of $\hat{L}^2$, but instead we will just present the eigenfunctions and eigenvalues,

$$
\hat{L}^2 Y_l^{m_l} (\theta, \phi) = \hbar^2 l(l+1)Y_l^{m_l} (\theta, \phi) \qquad l=0,1,2,\ldots m_l=0, \pm 1, \ldots, \pm l
$$

The functions [$Y_l^{m_l} (\theta, \phi)$](https://en.wikipedia.org/wiki/Spherical_harmonics) are called [spherical harmonics](https://mathworld.wolfram.com/SphericalHarmonic.html), and they are the fundamental vibrational modes of the surface of a spherical membrane. Note that these functions resemble s-orbitals ($l=0$), p-orbitals ($l=1$), d-orbitals ($l=2$), etc., and that the number of choices for $m_l$, $2l+1$, is equal to the number of $l$-type orbitals.

### The Radial Schrödinger equation in Spherical Coordinates
Using separation of variables, we write the wavefunction as:

$$
\psi_{n,l,m_l}(r,\theta,\phi) = R_{n,l}(r) Y_l^{m_l}(\theta,\phi)
$$

Inserting this expression into the Schrödinger equation, and exploiting the fact that the spherical harmonics are eigenfunctions of $\hat{L}^2$, one obtains the radial Schrödinger equation:

$$
\left(-\frac{\hbar^2}{2m} \left( \frac{d^2}{dr^2}
+ \frac{2}{r} \frac{d}{dr}\right)
      + \frac{\hbar^2 l(l+1)}{2mr^2} + V(r) \right)
      R_{n,l}(r)
= E_{n,l}R_{n,l}(r)
$$

Inside the sphere, $V(r) = 0$. Rearranging the radial Schrödinger equation for the interior of the sphere as a homogeneous linear differential equation,

$$
r^2 \frac{d^2R_{n,l}}{dr^2}
+ 2r \frac{dR_{n,l}}{dr}
+ \left( \frac{2mr^2E_{n,l}}{\hbar^2} - l(l+1) \right)
      R_{n,l}(r) = 0
$$

This equation strongly resembles the differential equations satisfied by the [spherical Bessel functions](https://en.wikipedia.org/wiki/Bessel_function#Spherical_Bessel_functions:_jn,_yn), $j_l(x)$

$$
x^2 \frac{d^2 j_l}{dx^2} + 2x \frac{dj_l}{dx} + \left(x^2 - l(l+1) \right)j_l(x) = 0
$$

The spherical Bessel functions are eigenfunctions for the particle-in-a-spherical-ball, but do not satisfy the boundary condition that the wavefunction be zero on the sphere, $R_{n,l}(a) = 0$. To satisfy this constraint, we propose

$$
R_{n,l}(r) = j_l(k r)
$$

Using this form in the radial Schrödinger equation, we have

$$
(kr)^2 \frac{d^2 j_l(kr)}{d(kr)^2}
+ 2kr \frac{d j_l(kr)}{d(kr)}
+ \left( \frac{2m(kr)^2E_{n,l}}{\hbar^2k^2} - l(l+1) \right)
      j_l(kr) = 0
$$

Referring back to the differential equation satisfied by the spherical Bessel functions, it is clear that this equation is satisfied when

$$
\frac{2m E_{n,l}}{k^2 \hbar^2} = 1
$$

or, equivalently,

$$
E_{n,l} = \frac{\hbar^2 k^2}{2m}
$$

where $k$ is chosen so that $j_l(ka) = 0$. If we label the zeros of the spherical Bessel functions,

$$
j_l(y_{n,l}) = 0 \qquad \qquad n=1,2,3,\ldots \\
y_{1,l} \lt y_{2,l} \lt y_{3,l} \lt \cdots
$$

then

$$
k_{n,l} = \frac{y_{n,l}}{a}
$$

and the energies of the particle-in-a-ball are

$$
E_{n,l} = \frac{\hbar^2 y_{n,l}^2}{2ma^2} = \frac{h^2 y_{n,l}^2}{8 m \pi^2 a^2}
$$

and the eigenfunctions of the particle-in-a-ball are:

$$
\psi_{n,l,m}(r,\theta,\phi) \propto j_l\left(\frac{y_{n,l}r}{a} \right) Y_l^{m_l}(\theta, \phi)
$$

Notice that the eigenenergies have the same form as those in the particle-in-a-disk and even the same as those for a particle-in-a-one-dimensional-box; the only difference is the identity of the function whose zeros we are considering.

## 📝 Exercise: Use the equation for the zeros of $\sin x$ to write the wavefunction and energy for the one-dimensional particle-in-a-box in a form similar to the expressions for the particle-in-a-disk and the particle-in-a-sphere.

### Solutions to the Schrödinger Equation for a Particle Confined to a Spherical Ball

The energies of a particle confined to a spherical ball of radius $a$ are:

$$
E_{n,l} = \frac{\hbar^2 y_{n,l}^2}{2ma^2} \qquad n=1,2,\ldots; \quad l=0,1,\ldots; \quad m=0, \pm1, \ldots, \pm l
$$

and its eigenfunctions are:

$$
\psi_{n,l,m}(r,\theta,\phi) \propto j_l\left(\frac{y_{n,l}r}{a} \right) Y_l^{m_l}(\theta, \phi)
$$

where $y_{n,l}$ are the zeros of the spherical Bessel function, $j_l(y_{n,l}) = 0$. The first spherical Bessel function, which corresponds to s-like solutions ($l=0$), is

$$
j_l(y) = \frac{\sin y}{y}
$$

and so

$$
y_{n,0} = n \pi
$$

This gives explicit and useful expressions for the $l=0$ wavefunctions and energies,

$$
E_{n,0} = \frac{h^2 n^2}{8 m a^2}
$$

and its eigenfunctions are:

$$
\psi_{n,0,0}(r,\theta,\phi) \propto \frac{a}{n \pi r} \sin \left( \frac{n \pi r}{a} \right)
$$

Notice that the $l=0$ energies are the same as in the one-dimensional particle-in-a-box and the eigenfunctions are very similar.

In atomic units, the energies of an electron confined to a spherical ball with radius $a$ Bohr are:

$$
E_{n,l} = \tfrac{y_{n,l}^2}{2a^2}
$$

The following code block computes these energies. It uses the relationship between the spherical Bessel functions and the ordinary Bessel functions,

$$
j_l(x) = \sqrt{\frac{\pi}{2x}} J_{l+\tfrac{1}{2}}(x)
$$

which indicates that the zeros of $j_l(x)$ and $J_{l+\tfrac{1}{2}}(x)$ occur the same places.

```python
# Define a function for the energy (in a.u.) of a particle in a spherical ball
# with length a, principle quantum number n, and angular quantum number l
# The length is input in Bohr (atomic units).
def compute_energy_ball(n, l, a):
    "Compute 1-dimensional particle-in-a-spherical-ball energy."
    #Compute the energy from the n-th zero.
    return float((mpmath.besseljzero(l+0.5,n))**2/ (2 * a**2))

#This next bit of code just prints out the energy in atomic units
def print_energy_ball(a, n, l):
    print(f'The energy of an electron confined to a ball with radius {a:.2f} a.u.,'
       f' principle quantum number {n}, and angular quantum number {l}'
       f' is {compute_energy_ball(n, l, a):5.2f} a.u..')

#Principle quantum number slider:
n = 1

#Angular quantum number slider:
l = 0

#Box length slider:
a = 1

print_energy_ball(a, n, l)
```

    The energy of an electron confined to a ball with radius 1.00 a.u., principle quantum number 1, and angular quantum number 0 is  4.93 a.u..

## 📝 Exercise: For the hydrogen atom, the 2s orbital ($n=2$, $l=0$) and 2p orbitals ($n=2$,$l=1$,$m_l=-1,0,1$) have the same energy. Is this true for the particle-in-a-ball?

## 🪞 Self-Reflection
- Can you think of other physical or chemical systems where a multi-dimensional particle-in-a-box Hamiltonian would be appropriate? What shape would the box be?
- Can you think of another chemical system where separation of variables would be useful?
- Explain why separation of variables is consistent with the Born Postulate that the square-magnitude of a particle's wavefunction is the probability distribution function for the particle.
- What is the expression for the zero-point energy and ground-state wavefunction of an electron in a 4-dimensional box? Can you identify some states of the 4-dimensional box with especially high degeneracy?
- What is the degeneracy of the k-th excited state of a particle confined to a circular disk? What is the degeneracy of the k-th excited state of a particle confined in a spherical ball?
- Write a Python function that computes the normalization constant for the particle-in-a-disk and the particle-in-a-sphere.

## 🤔 Thought-Provoking Questions
- How would you write the Hamiltonian for two electrons confined to a box? Could you solve this system with separation of variables? Why or why not?
- Write the time-independent Schrödinger equation for an electron in an cylindrical box. What are its eigenfunctions and eigenvalues?
- What would the time-independent Schrödinger equation for electrons in an elliptical box look like? (You may find it useful to reference [elliptical](https://en.wikipedia.org/wiki/Elliptic_coordinate_system) and [ellipsoidal](https://en.wikipedia.org/wiki/Ellipsoidal_coordinates) coordinates.
- Construct an example of a four-fold *accidental* degeneracy for a particle in a 2-dimensional rectangular (not square!) box.
- If there is any degenerate state (either accidental or due to symmetry) for the multi-dimensional particle-in-a-box, then there are always an infinite number of other degenerate states. Why?
- Consider an electron confined to a circular harmonic well, $V(r) = k r^2$. What is the angular kinetic energy and angular wavefunction for this system?

## 🔁 Recapitulation
- Write the Hamiltonian, time-independent Schrödinger equation, eigenfunctions, and eigenvalues for two-dimensional and three-dimensional particles in a box.
- What is the definition of degeneracy? How does an "accidental" degeneracy differ from an ordinary degeneracy?
- What is the zero-point energy for an electron in a circle and an electron in a sphere?
- What are the spherical harmonics?
- Describe the technique of separation of variables? When can it be applied?
- What is the Laplacian operator in Cartesian coordinates? In spherical coordinates?
- What are *boundary conditions* and how are they important in quantum mechanics?

## 🔮 Next Up...
- 1-electron atoms
- Approximate methods for quantum mechanics
- Multielectron particle-in-a-box

## 📚 References
My favorite sources for this material are:
- [Randy's book](https://github.com/PaulWAyers/IntroQChem/blob/main/documents/DumontBook.pdf?raw=true) (See Chapter 3)
- Also see my (pdf) class [notes]
(https://github.com/PaulWAyers/IntroQChem/blob/main/documents/PinBox.pdf?raw=true).
- [McQuarrie and Simon summary](https://chem.libretexts.org/Bookshelves/Physical_and_Theoretical_Chemistry_Textbook_Maps/Map%3A_Physical_Chemistry_(McQuarrie_and_Simon)/03%3A_The_Schrodinger_Equation_and_a_Particle_in_a_Box)
- [Wolfram solutions for particle in a circle](https://demonstrations.wolfram.com/ParticleInAnInfiniteCircularWell/)
- [Meticulous solution for a particle confined to a circular disk](https://opencommons.uconn.edu/cgi/viewcontent.cgi?article=1013&context=chem_educ)
- [General discussion of the particle-in-a-region, which is the same as the classical wave equation](http://galileo.phys.virginia.edu/classes/252/Classical_Waves/Classical_Waves.html)
- [More on the radial Schrödinger equation](https://quantummechanics.ucsd.edu/ph130a/130_notes/node222.html)
- Python tutorial ([part 1](https://physicspython.wordpress.com/2020/05/28/the-problem-of-the-hydrogen-atom-part-1/) and [part 2](https://physicspython.wordpress.com/2020/06/04/the-problem-of-the-hydrogen-atom-part-2/)) on the Hydrogen atom.

There are also some excellent wikipedia articles:
- [Particle in a Sphere](https://en.wikipedia.org/wiki/Particle_in_a_spherically_symmetric_potential)
- [Other exactly solvable models](https://en.wikipedia.org/wiki/List_of_quantum-mechanical_systems_with_analytical_solutions)


```python
import sympy as sp
sp.E + sp.pi + sp.I
```

$\displaystyle e + \pi + i$

```python
sp.oo
```

$\displaystyle \infty$

```python
x,y,z = sp.symbols('x y z')
sp.log(x) + sp.exp(x) + sp.sin(x) + sp.asin(x) + sp.sinh(x)
```

$\displaystyle e^{x} + \log{\left(x \right)} + \sin{\left(x \right)} + \sinh{\left(x \right)} + \operatorname{asin}{\left(x \right)}$

```python
eq = x**2 + 3
sp.solveset(eq,x)

```

$\displaystyle \left\{- \sqrt{3} i, \sqrt{3} i\right\}$

```python
eq = sp.Eq(x**2+3,0)
sp.solveset(eq)
```

$\displaystyle \left\{- \sqrt{3} i, \sqrt{3} i\right\}$

```python
sp.solveset(sp.sin(x)+sp.cos(x),x)
```

$\displaystyle \left\{2 n \pi + \frac{3 \pi}{4}\; \middle|\; n \in \mathbb{Z}\right\} \cup \left\{2 n \pi + \frac{7 \pi}{4}\; \middle|\; n \in \mathbb{Z}\right\}$

```python
sp.linsolve([sp.Eq(3*x+2*y,4),sp.Eq(1*x+9*y,8)],x,y)
```

$\displaystyle \left\{\left( \frac{4}{5}, \  \frac{4}{5}\right)\right\}$

# Functions

> 인수분해

        * sp.factor() - Factor expressions

> 전개하기

        * sp.expand() - Expands expr

> 분수 약분, 부분분수로

        * sp.cancel() - Puts rational function in standard canonical form
        * sp.apart()  - Perform a partial fraction decomposition for a function

> 최대한 간단하게

        * sp.simplify() - A general simplification function

> 묶어내기

        * sp.collect(expr,x) - arrage of x(or sp.I)

```python
# create a polynomial
poly = x**2 + 5*x + 6
poly.factor()
```

$\displaystyle \left(x + 2\right) \left(x + 3\right)$

```python
poly = poly.factor()
poly.expand()
```

$\displaystyle x^{2} + 5 x + 6$

```python
trig = (sp.cos(x) + sp.sin(y))**2 + sp.cos(x)**2
trig
```

$\displaystyle \left(\sin{\left(y \right)} + \cos{\left(x \right)}\right)^{2} + \cos^{2}{\left(x \right)}$

```python
trig.expand()
```

$\displaystyle \sin^{2}{\left(y \right)} + 2 \sin{\left(y \right)} \cos{\left(x \right)} + 2 \cos^{2}{\left(x \right)}$

```python
trig.factor()
```

$\displaystyle \sin^{2}{\left(y \right)} + 2 \sin{\left(y \right)} \cos{\left(x \right)} + 2 \cos^{2}{\left(x \right)}$

```python
trig.simplify()
```

$\displaystyle \left(\sin{\left(y \right)} + \cos{\left(x \right)}\right)^{2} + \cos^{2}{\left(x \right)}$

```python
p = x**3 + 10*x**2 + 31*x + 30
q = x**2 + 12*x + 35
f = p/q
f

```

$\displaystyle \frac{x^{3} + 10 x^{2} + 31 x + 30}{x^{2} + 12 x + 35}$

```python
f.cancel()
```

$\displaystyle \frac{x^{2} + 5 x + 6}{x + 7}$

```python
f.apart()
```

$\displaystyle x - 2 + \frac{20}{x + 7}$

```python
f.simplify()

```

$\displaystyle \frac{x^{2} + 5 x + 6}{x + 7}$

```python
expr = sp.exp(x+y) + (sp.cos(x) + sp.sin(x))**2
expr.simplify()
```

$\displaystyle e^{x + y} + \sin{\left(2 x \right)} + 1$

```python
expr = sp.pi + x**2
expr
```

$\displaystyle x^{2} + \pi$

```python
sp.N(expr)
```

$\displaystyle x^{2} + 3.14159265358979$

# Derivatives
    sp.diff()
    .rewirte()

```python
expr = sp.exp(2*x) + sp.sin(x)
expr
```

$\displaystyle e^{2 x} + \sin{\left(x \right)}$

```python
expr.diff()
```

$\displaystyle 2 e^{2 x} + \cos{\left(x \right)}$

```python
sp.diff(expr,x)
```

$\displaystyle 2 e^{2 x} + \cos{\left(x \right)}$

```python
sp.diff(sp.diff(expr))
```

$\displaystyle 4 e^{2 x} - \sin{\left(x \right)}$

```python
sp.diff(expr,x,x)
```

$\displaystyle 4 e^{2 x} - \sin{\left(x \right)}$

```python
expr = sp.exp(sp.sinh(x)) / sp.exp(sp.exp(x) / 2)
expr
```

$\displaystyle e^{- \frac{e^{x}}{2}} e^{\sinh{\left(x \right)}}$

```python
expr.rewrite(sp.exp)
```

$\displaystyle e^{\frac{e^{x}}{2} - \frac{e^{- x}}{2}} e^{- \frac{e^{x}}{2}}$

```python
expr.simplify()
```

$\displaystyle e^{- \frac{e^{x}}{2} + \sinh{\left(x \right)}}$

```python
expr.expand()
```

$\displaystyle e^{- \frac{e^{x}}{2}} e^{\sinh{\left(x \right)}}$

```python
two_var = sp.cos(x)*sp.cot(2*y)**2
two_var
```

$\displaystyle \cos{\left(x \right)} \cot^{2}{\left(2 y \right)}$

```python
two_var.diff(y)
```

$\displaystyle \left(- 4 \cot^{2}{\left(2 y \right)} - 4\right) \cos{\left(x \right)} \cot{\left(2 y \right)}$

```python
two_var.diff(y).rewrite(sp.sin)
```

$\displaystyle \frac{\left(-4 - \frac{\sin^{2}{\left(4 y \right)}}{\sin^{4}{\left(2 y \right)}}\right) \sin{\left(4 y \right)} \sin{\left(x + \frac{\pi}{2} \right)}}{2 \sin^{2}{\left(2 y \right)}}$

```python
two_var.diff(y).simplify()
```

$\displaystyle - \frac{4 \cos{\left(x \right)} \cot{\left(2 y \right)}}{\sin^{2}{\left(2 y \right)}}$

```python
two_var.diff(y,2,x,3)
```

$\displaystyle 8 \left(\cot^{2}{\left(2 y \right)} + 1\right) \left(3 \cot^{2}{\left(2 y \right)} + 1\right) \sin{\left(x \right)}$

```python
two_var.diff(x,3,y,2)
```

$\displaystyle 8 \left(\cot^{2}{\left(2 y \right)} + 1\right) \left(3 \cot^{2}{\left(2 y \right)} + 1\right) \sin{\left(x \right)}$

# Integrals
    sp.integrate()
    sp.integrate(fx,(x,start,end))

```python
w = x*y*z**2
w
```

$\displaystyle x y z^{2}$

```python
sp.integrate(w,x)
```

$\displaystyle \frac{x^{2} y z^{2}}{2}$

```python
sp.integrate(w,y)
```

$\displaystyle \frac{x y^{2} z^{2}}{2}$

```python
# indefinite integral
sp.integrate(w,x,y)
```

$\displaystyle \frac{x^{2} y^{2} z^{2}}{4}$

```python
# indefinite integral
sp.integrate(sp.integrate(w,x),y)
```

$\displaystyle \frac{x^{2} y^{2} z^{2}}{4}$

```python
# definate integral
sp.integrate(w,(x,0,1),(y,1,5),(z,0,3))
```

$\displaystyle 54$

# Limits and Series
    sp.limit()
    sp.series()
    .remove()   - remove the "big O" from the Taylor series

```python
expr = 1 / x
expr
```

$\displaystyle \frac{1}{x}$

```python
sp.limit(expr,x,0)
```

$\displaystyle \infty$

```python
sp.limit(expr,x,0,'-')
```

$\displaystyle -\infty$

```python
sp.limit(expr,x,0,'+-')
```

$\displaystyle \tilde{\infty}$

```python
sp.series(sp.sin(x),x,sp.pi/2)
```

$\displaystyle 1 - \frac{\left(x - \frac{\pi}{2}\right)^{2}}{2} + \frac{\left(x - \frac{\pi}{2}\right)^{4}}{24} + O\left(\left(x - \frac{\pi}{2}\right)^{6}; x\rightarrow \frac{\pi}{2}\right)$

# Taylor series

```python
expr = sp.sin(x)
expr
```

$\displaystyle \sin{\left(x \right)}$

```python
sp.series(expr,x,0)
```

$\displaystyle x - \frac{x^{3}}{6} + \frac{x^{5}}{120} + O\left(x^{6}\right)$

```python
sp.series(sp.cos(x),x,0)
```

$\displaystyle 1 - \frac{x^{2}}{2} + \frac{x^{4}}{24} + O\left(x^{6}\right)$

```python
sp.series(sp.exp(x),x,0)
```

$\displaystyle 1 + x + \frac{x^{2}}{2} + \frac{x^{3}}{6} + \frac{x^{4}}{24} + \frac{x^{5}}{120} + O\left(x^{6}\right)$

```python
sp.series(sp.exp(sp.sin(x)),x,0)
```

$\displaystyle 1 + x + \frac{x^{2}}{2} - \frac{x^{4}}{8} - \frac{x^{5}}{15} + O\left(x^{6}\right)$

```python
sp.series(sp.exp(x*sp.I),x,0)
```

$\displaystyle 1 + i x - \frac{x^{2}}{2} - \frac{i x^{3}}{6} + \frac{x^{4}}{24} + \frac{i x^{5}}{120} + O\left(x^{6}\right)$

# f(x)
near x=a, $$f(x) = a_0 + a_1(x-a) + a_2(x-a)^2 + a_3(x-a)^3 + \dots + a_n(x-a)^n + \dots \\
x = a , f(a) = a_0 $$

$$ f'(x-a) = 0 + a_1 + (a_2*2)(x-a) + a_3*3(x-a)^2 + a_4*4(x-a)^3 + a_5*5(x-a)^4 \dots \\
x = a ,\, f'(a) = (a_1) $$

$$ f''(x-a) = 0 + 0 + (a_2*2) + a_3*3*2(x-a)^1 + a_4*4*3(x-a)^2 + a_5*5*4(x-a)^3 \dots \\
x = a ,\, f''(a) = (a_2) * 2 $$

$$ f^{3}(x-a) = 0 + 0 + 0 + a_3*3*2 + a_4*4*3*2(x-a)^1 + a_5*5*4*3(x-a)^2 \dots \\
x = a ,\, f'''(a) = (a_3) *3 * 2 $$

$$ \because f(x) = \frac{f(a)}{0!}(x-a)^0 + \frac{f'(a)}{1!}(x-a)^1 + \frac{f''(a)}{2!}(x-a)^2 + \frac{f'''(a)}{3!}(x-a)^3 + \frac{f^{4}(a)}{4!}(x-a)^4 \dots $$

$$ f(x) = \sum_{n =0}^{\infty}\, \frac{f^{n}(a)}{n!}{(x-a)^n} $$

# exp
$$ e^x = \frac{e^0}{0!}x^0 + \frac {e^0}{1!}x^1 + \frac{e^0}{2!}x^2 + \frac{e^0}{3!}x^3 + \dots
$$

$$ e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \dots
$$

# cos (x)
$$ \cos(x) = -sin(0) + \frac{-cos(0)}{1!}x^1 + \frac{sin(0)}{2!}x^2 + \frac{cos(0)}{3!}x^3 + \frac{-sin(0)}{4!}x^4 + \frac{-cos(0)}{5!}x^5 + \frac{sin(0)}{6!}x^6 + \dots $$

$$ \cos(x) = 0 + -1x + 0 + \frac{1}{3!}x^3 + 0 + \frac{-1}{5!}x^5 + 0 + \dots
$$

# sin (x)
$$ \sin(x) = cos(0) + \frac{-sin(0)}{1!}x^1 + \frac{-cos(0)}{2!}x^2 + \frac{sin(0)}{3!}x^3 + \frac{cos(0)}{4!}x^4 + \frac{-sin(0)}{5!}x^5 + \frac{-cos(0)}{6!}x^6 + \dots
$$

$$ \sin(x) = 1 + 0 + \frac{-1}{2!}x^2 + 0 + \frac{1}{4!}x^4 + 0 + \frac{-1}{6!}x^6
$$

# eulor equation
$$ e^{ix} = \cos(x) + i(\sin(x)) \\
x = \pi, \\
e^{i\pi} = \cos(\pi) +  i (\sin{\pi}) \\
e^{i\pi} = -1 \\
x = \frac{\pi}{2}, \\
e^{i\frac{\pi}{2}} = i \\
$$

```python
sp.series(sp.E**x,x,0,n=10)
```

$\displaystyle 1 + x + \frac{x^{2}}{2} + \frac{x^{3}}{6} + \frac{x^{4}}{24} + \frac{x^{5}}{120} + \frac{x^{6}}{720} + \frac{x^{7}}{5040} + \frac{x^{8}}{40320} + \frac{x^{9}}{362880} + O\left(x^{10}\right)$

```python
sp.series(sp.cos(x),x,0,n=10)
```

$\displaystyle 1 - \frac{x^{2}}{2} + \frac{x^{4}}{24} - \frac{x^{6}}{720} + \frac{x^{8}}{40320} + O\left(x^{10}\right)$

```python
sp.series(sp.sin(x),x,0,n=10)
```

$\displaystyle x - \frac{x^{3}}{6} + \frac{x^{5}}{120} - \frac{x^{7}}{5040} + \frac{x^{9}}{362880} + O\left(x^{10}\right)$

```python
sp.series(sp.I*sp.sin(x),x, 0 , 10)
```

$\displaystyle i x - \frac{i x^{3}}{6} + \frac{i x^{5}}{120} - \frac{i x^{7}}{5040} + \frac{i x^{9}}{362880} + O\left(x^{10}\right)$

```python
expr = sp.series(sp.E**(sp.I*x), x, 0 , 5)
sp.collect(expr,sp.I)
```

$\displaystyle 1 + i \left(x - \frac{x^{3}}{6} + O\left(x^{5}\right)\right) - \frac{x^{2}}{2} + \frac{x^{4}}{24} + O\left(x^{5}\right)$

```python
expr.removeO()
```

$\displaystyle \frac{x^{4}}{24} - \frac{i x^{3}}{6} - \frac{x^{2}}{2} + i x + 1$

# Ordinary Differential Euqation
    .rhs - right-hand side of an equation
    .lhs - left-hand side of an equation
    sp.dsolve() - Soving a differential eqation
    sp.Function() - Creating an unspecified function

```python
f = sp.Function('f')(x)
f
```

$\displaystyle f{\left(x \right)}$

```python
f.diff()
```

$\displaystyle \frac{d}{d x} f{\left(x \right)}$

```python
f.integrate()
```

$\displaystyle \int f{\left(x \right)}\, dx$

```python
diff_eq = sp.Eq(x*f.diff(x,x) + f.diff(x), x**3)
diff_eq
```

$\displaystyle x \frac{d^{2}}{d x^{2}} f{\left(x \right)} + \frac{d}{d x} f{\left(x \right)} = x^{3}$

```python
diff_eq.rhs
```

$\displaystyle x^{3}$

```python
diff_eq.lhs
```

$\displaystyle x \frac{d^{2}}{d x^{2}} f{\left(x \right)} + \frac{d}{d x} f{\left(x \right)}$

```python
sol = sp.dsolve(diff_eq,f)
sol
```

$\displaystyle f{\left(x \right)} = C_{1} + C_{2} \log{\left(x \right)} + \frac{x^{4}}{16}$

```python
type(sol)
```

    sympy.core.relational.Equality

```python
exp = sol.rhs
exp
```

$\displaystyle C_{1} + C_{2} \log{\left(x \right)} + \frac{x^{4}}{16}$

```python
exp.free_symbols
```

    {C1, C2, x}

```python
tuple(exp.free_symbols)
```

    (x, C2, C1)

```python
_, c2,c1 = tuple(exp.free_symbols)
```

```python
exp.subs(c1,0).subs(c2,1)
```

$\displaystyle \frac{x^{4}}{16} + \log{\left(x \right)}$

# Initial Condition
    f(1) = 0, f'(2) = 1

```python
ics = {f.subs(x,1):0, f.diff().subs(x,2):1}
ics
```

    {f(1): 0, Subs(Derivative(f(x), x), x, 2): 1}

```python
ivp = sp.dsolve(diff_eq, ics=ics).rhs
ivp
```

$\displaystyle \frac{x^{4}}{16} - 2 \log{\left(x \right)} - \frac{1}{16}$

```python
ivp.diff().subs(x,2)
```

$\displaystyle 1$

```python
ivp.subs(x,1)
```

$\displaystyle 0$

```python
(x*ivp.diff(x,x) + ivp.diff()).simplify()
```

$\displaystyle x^{3}$

# Numerical
    sp.evalf() - Evaluats a sympy numerical expressions to a float
    sp.lamdify() - Create a "lamddified function" out of an expession

```python
expr = sp.pi * x**2 + 5*x + sp.E
expr
```

$\displaystyle \pi x^{2} + 5 x + e$

```python
value = expr.subs(x,1)
value
```

$\displaystyle e + \pi + 5$

```python
value.evalf()
```

$\displaystyle 10.8598744820488$

```python
value.evalf(8)
```

$\displaystyle 10.859874$

```python
sp.N(value)
```

$\displaystyle 10.8598744820488$

```python
sp.N(value,8)
```

$\displaystyle 10.859874$

```python
lambdified_expr = sp.lambdify(x, sp.pi * x**2 + 5*x + sp.E)
lambdified_expr
```

    <function _lambdifygenerated(x)>

```python
lambdified_expr(3)
```

    45.99261571076719

```python
import numpy as np
p = np.linspace(-20,20,1000)
```

```python
lambdified_expr(p)
```

    array([1.15935534e+03, 1.15452900e+03, 1.14971273e+03, 1.14490653e+03,
           1.14011041e+03, 1.13532436e+03, 1.13054838e+03, 1.12578248e+03,
           1.12102665e+03, 1.11628089e+03, 1.11154521e+03, 1.10681960e+03,
           1.10210406e+03, 1.09739860e+03, 1.09270321e+03, 1.08801789e+03,
           1.08334264e+03, 1.07867747e+03, 1.07402237e+03, 1.06937735e+03,
           1.06474240e+03, 1.06011752e+03, 1.05550271e+03, 1.05089798e+03,
           1.04630332e+03, 1.04171874e+03, 1.03714423e+03, 1.03257979e+03,
           1.02802542e+03, 1.02348113e+03, 1.01894691e+03, 1.01442276e+03,
           1.00990869e+03, 1.00540469e+03, 1.00091076e+03, 9.96426912e+02,
           9.91953132e+02, 9.87489425e+02, 9.83035792e+02, 9.78592231e+02,
           9.74158745e+02, 9.69735331e+02, 9.65321990e+02, 9.60918723e+02,
           9.56525529e+02, 9.52142408e+02, 9.47769361e+02, 9.43406387e+02,
           9.39053486e+02, 9.34710658e+02, 9.30377903e+02, 9.26055222e+02,
           9.21742614e+02, 9.17440079e+02, 9.13147617e+02, 9.08865229e+02,
           9.04592913e+02, 9.00330671e+02, 8.96078503e+02, 8.91836407e+02,
           8.87604385e+02, 8.83382436e+02, 8.79170560e+02, 8.74968758e+02,
           8.70777028e+02, 8.66595372e+02, 8.62423789e+02, 8.58262280e+02,
           8.54110843e+02, 8.49969480e+02, 8.45838190e+02, 8.41716973e+02,
           8.37605830e+02, 8.33504760e+02, 8.29413763e+02, 8.25332839e+02,
           8.21261988e+02, 8.17201211e+02, 8.13150507e+02, 8.09109876e+02,
           8.05079318e+02, 8.01058834e+02, 7.97048423e+02, 7.93048085e+02,
           7.89057820e+02, 7.85077629e+02, 7.81107511e+02, 7.77147466e+02,
           7.73197494e+02, 7.69257595e+02, 7.65327770e+02, 7.61408018e+02,
           7.57498339e+02, 7.53598734e+02, 7.49709201e+02, 7.45829742e+02,
           7.41960356e+02, 7.38101044e+02, 7.34251804e+02, 7.30412638e+02,
           7.26583545e+02, 7.22764525e+02, 7.18955579e+02, 7.15156706e+02,
           7.11367906e+02, 7.07589179e+02, 7.03820525e+02, 7.00061945e+02,
           6.96313438e+02, 6.92575004e+02, 6.88846643e+02, 6.85128356e+02,
           6.81420142e+02, 6.77722001e+02, 6.74033933e+02, 6.70355939e+02,
           6.66688018e+02, 6.63030170e+02, 6.59382395e+02, 6.55744693e+02,
           6.52117065e+02, 6.48499510e+02, 6.44892028e+02, 6.41294619e+02,
           6.37707284e+02, 6.34130022e+02, 6.30562833e+02, 6.27005717e+02,
           6.23458675e+02, 6.19921706e+02, 6.16394810e+02, 6.12877987e+02,
           6.09371238e+02, 6.05874561e+02, 6.02387958e+02, 5.98911428e+02,
           5.95444972e+02, 5.91988589e+02, 5.88542278e+02, 5.85106042e+02,
           5.81679878e+02, 5.78263788e+02, 5.74857770e+02, 5.71461826e+02,
           5.68075956e+02, 5.64700158e+02, 5.61334434e+02, 5.57978783e+02,
           5.54633205e+02, 5.51297701e+02, 5.47972269e+02, 5.44656911e+02,
           5.41351626e+02, 5.38056415e+02, 5.34771276e+02, 5.31496211e+02,
           5.28231219e+02, 5.24976301e+02, 5.21731455e+02, 5.18496683e+02,
           5.15271984e+02, 5.12057358e+02, 5.08852806e+02, 5.05658327e+02,
           5.02473921e+02, 4.99299588e+02, 4.96135328e+02, 4.92981142e+02,
           4.89837029e+02, 4.86702989e+02, 4.83579022e+02, 4.80465129e+02,
           4.77361309e+02, 4.74267562e+02, 4.71183888e+02, 4.68110287e+02,
           4.65046760e+02, 4.61993306e+02, 4.58949925e+02, 4.55916618e+02,
           4.52893383e+02, 4.49880222e+02, 4.46877134e+02, 4.43884120e+02,
           4.40901178e+02, 4.37928310e+02, 4.34965515e+02, 4.32012794e+02,
           4.29070145e+02, 4.26137570e+02, 4.23215068e+02, 4.20302639e+02,
           4.17400284e+02, 4.14508001e+02, 4.11625792e+02, 4.08753657e+02,
           4.05891594e+02, 4.03039605e+02, 4.00197688e+02, 3.97365846e+02,
           3.94544076e+02, 3.91732379e+02, 3.88930756e+02, 3.86139206e+02,
           3.83357730e+02, 3.80586326e+02, 3.77824996e+02, 3.75073739e+02,
           3.72332555e+02, 3.69601444e+02, 3.66880407e+02, 3.64169443e+02,
           3.61468552e+02, 3.58777734e+02, 3.56096990e+02, 3.53426319e+02,
           3.50765721e+02, 3.48115196e+02, 3.45474745e+02, 3.42844366e+02,
           3.40224061e+02, 3.37613830e+02, 3.35013671e+02, 3.32423586e+02,
           3.29843574e+02, 3.27273635e+02, 3.24713769e+02, 3.22163977e+02,
           3.19624258e+02, 3.17094612e+02, 3.14575039e+02, 3.12065540e+02,
           3.09566114e+02, 3.07076761e+02, 3.04597481e+02, 3.02128274e+02,
           2.99669141e+02, 2.97220081e+02, 2.94781094e+02, 2.92352181e+02,
           2.89933340e+02, 2.87524573e+02, 2.85125879e+02, 2.82737259e+02,
           2.80358711e+02, 2.77990237e+02, 2.75631836e+02, 2.73283508e+02,
           2.70945254e+02, 2.68617073e+02, 2.66298965e+02, 2.63990930e+02,
           2.61692968e+02, 2.59405080e+02, 2.57127265e+02, 2.54859523e+02,
           2.52601854e+02, 2.50354259e+02, 2.48116737e+02, 2.45889288e+02,
           2.43671912e+02, 2.41464610e+02, 2.39267380e+02, 2.37080224e+02,
           2.34903142e+02, 2.32736132e+02, 2.30579196e+02, 2.28432333e+02,
           2.26295543e+02, 2.24168826e+02, 2.22052183e+02, 2.19945613e+02,
           2.17849116e+02, 2.15762692e+02, 2.13686342e+02, 2.11620065e+02,
           2.09563861e+02, 2.07517730e+02, 2.05481673e+02, 2.03455688e+02,
           2.01439777e+02, 1.99433939e+02, 1.97438175e+02, 1.95452484e+02,
           1.93476865e+02, 1.91511321e+02, 1.89555849e+02, 1.87610450e+02,
           1.85675125e+02, 1.83749873e+02, 1.81834695e+02, 1.79929589e+02,
           1.78034557e+02, 1.76149598e+02, 1.74274712e+02, 1.72409900e+02,
           1.70555160e+02, 1.68710494e+02, 1.66875901e+02, 1.65051382e+02,
           1.63236935e+02, 1.61432562e+02, 1.59638262e+02, 1.57854036e+02,
           1.56079882e+02, 1.54315802e+02, 1.52561795e+02, 1.50817861e+02,
           1.49084001e+02, 1.47360214e+02, 1.45646499e+02, 1.43942859e+02,
           1.42249291e+02, 1.40565797e+02, 1.38892376e+02, 1.37229028e+02,
           1.35575753e+02, 1.33932552e+02, 1.32299423e+02, 1.30676369e+02,
           1.29063387e+02, 1.27460478e+02, 1.25867643e+02, 1.24284881e+02,
           1.22712192e+02, 1.21149577e+02, 1.19597034e+02, 1.18054565e+02,
           1.16522169e+02, 1.14999847e+02, 1.13487597e+02, 1.11985421e+02,
           1.10493318e+02, 1.09011289e+02, 1.07539332e+02, 1.06077449e+02,
           1.04625639e+02, 1.03183902e+02, 1.01752239e+02, 1.00330648e+02,
           9.89191313e+01, 9.75176875e+01, 9.61263169e+01, 9.47450195e+01,
           9.33737954e+01, 9.20126445e+01, 9.06615669e+01, 8.93205624e+01,
           8.79896312e+01, 8.66687733e+01, 8.53579885e+01, 8.40572770e+01,
           8.27666388e+01, 8.14860737e+01, 8.02155819e+01, 7.89551634e+01,
           7.77048180e+01, 7.64645459e+01, 7.52343471e+01, 7.40142214e+01,
           7.28041690e+01, 7.16041898e+01, 7.04142839e+01, 6.92344512e+01,
           6.80646917e+01, 6.69050055e+01, 6.57553925e+01, 6.46158527e+01,
           6.34863862e+01, 6.23669929e+01, 6.12576728e+01, 6.01584259e+01,
           5.90692523e+01, 5.79901520e+01, 5.69211248e+01, 5.58621709e+01,
           5.48132902e+01, 5.37744828e+01, 5.27457486e+01, 5.17270876e+01,
           5.07184999e+01, 4.97199853e+01, 4.87315441e+01, 4.77531760e+01,
           4.67848812e+01, 4.58266596e+01, 4.48785113e+01, 4.39404362e+01,
           4.30124343e+01, 4.20945056e+01, 4.11866502e+01, 4.02888680e+01,
           3.94011591e+01, 3.85235233e+01, 3.76559609e+01, 3.67984716e+01,
           3.59510556e+01, 3.51137128e+01, 3.42864432e+01, 3.34692469e+01,
           3.26621238e+01, 3.18650740e+01, 3.10780974e+01, 3.03011940e+01,
           2.95343638e+01, 2.87776069e+01, 2.80309232e+01, 2.72943127e+01,
           2.65677755e+01, 2.58513115e+01, 2.51449208e+01, 2.44486032e+01,
           2.37623589e+01, 2.30861879e+01, 2.24200901e+01, 2.17640655e+01,
           2.11181141e+01, 2.04822360e+01, 1.98564311e+01, 1.92406994e+01,
           1.86350410e+01, 1.80394558e+01, 1.74539438e+01, 1.68785051e+01,
           1.63131396e+01, 1.57578473e+01, 1.52126283e+01, 1.46774825e+01,
           1.41524099e+01, 1.36374106e+01, 1.31324845e+01, 1.26376316e+01,
           1.21528520e+01, 1.16781456e+01, 1.12135124e+01, 1.07589525e+01,
           1.03144658e+01, 9.88005229e+00, 9.45571205e+00, 9.04144505e+00,
           8.63725128e+00, 8.24313074e+00, 7.85908343e+00, 7.48510935e+00,
           7.12120851e+00, 6.76738090e+00, 6.42362653e+00, 6.08994539e+00,
           5.76633748e+00, 5.45280280e+00, 5.14934136e+00, 4.85595314e+00,
           4.57263817e+00, 4.29939642e+00, 4.03622791e+00, 3.78313263e+00,
           3.54011058e+00, 3.30716177e+00, 3.08428619e+00, 2.87148384e+00,
           2.66875472e+00, 2.47609884e+00, 2.29351619e+00, 2.12100678e+00,
           1.95857059e+00, 1.80620764e+00, 1.66391792e+00, 1.53170144e+00,
           1.40955819e+00, 1.29748817e+00, 1.19549138e+00, 1.10356783e+00,
           1.02171751e+00, 9.49940420e-01, 8.88236565e-01, 8.36605943e-01,
           7.95048554e-01, 7.63564398e-01, 7.42153474e-01, 7.30815784e-01,
           7.29551327e-01, 7.38360102e-01, 7.57242110e-01, 7.86197351e-01,
           8.25225826e-01, 8.74327532e-01, 9.33502472e-01, 1.00275065e+00,
           1.08207205e+00, 1.17146669e+00, 1.27093456e+00, 1.38047566e+00,
           1.50009000e+00, 1.62977757e+00, 1.76953837e+00, 1.91937241e+00,
           2.07927968e+00, 2.24926018e+00, 2.42931392e+00, 2.61944088e+00,
           2.81964108e+00, 3.02991452e+00, 3.25026118e+00, 3.48068108e+00,
           3.72117421e+00, 3.97174058e+00, 4.23238017e+00, 4.50309300e+00,
           4.78387907e+00, 5.07473836e+00, 5.37567089e+00, 5.68667666e+00,
           6.00775565e+00, 6.33890788e+00, 6.68013334e+00, 7.03143203e+00,
           7.39280396e+00, 7.76424912e+00, 8.14576751e+00, 8.53735913e+00,
           8.93902399e+00, 9.35076208e+00, 9.77257341e+00, 1.02044580e+01,
           1.06464158e+01, 1.10984468e+01, 1.15605510e+01, 1.20327285e+01,
           1.25149792e+01, 1.30073032e+01, 1.35097004e+01, 1.40221708e+01,
           1.45447145e+01, 1.50773313e+01, 1.56200215e+01, 1.61727848e+01,
           1.67356214e+01, 1.73085312e+01, 1.78915143e+01, 1.84845705e+01,
           1.90877001e+01, 1.97009028e+01, 2.03241788e+01, 2.09575280e+01,
           2.16009504e+01, 2.22544461e+01, 2.29180150e+01, 2.35916572e+01,
           2.42753726e+01, 2.49691612e+01, 2.56730230e+01, 2.63869581e+01,
           2.71109664e+01, 2.78450480e+01, 2.85892027e+01, 2.93434307e+01,
           3.01077320e+01, 3.08821065e+01, 3.16665542e+01, 3.24610751e+01,
           3.32656693e+01, 3.40803367e+01, 3.49050773e+01, 3.57398912e+01,
           3.65847783e+01, 3.74397386e+01, 3.83047722e+01, 3.91798790e+01,
           4.00650590e+01, 4.09603123e+01, 4.18656388e+01, 4.27810385e+01,
           4.37065115e+01, 4.46420577e+01, 4.55876772e+01, 4.65433698e+01,
           4.75091357e+01, 4.84849748e+01, 4.94708872e+01, 5.04668728e+01,
           5.14729316e+01, 5.24890637e+01, 5.35152690e+01, 5.45515475e+01,
           5.55978993e+01, 5.66543243e+01, 5.77208225e+01, 5.87973940e+01,
           5.98840387e+01, 6.09807566e+01, 6.20875478e+01, 6.32044122e+01,
           6.43313498e+01, 6.54683606e+01, 6.66154447e+01, 6.77726021e+01,
           6.89398326e+01, 7.01171364e+01, 7.13045134e+01, 7.25019637e+01,
           7.37094872e+01, 7.49270839e+01, 7.61547538e+01, 7.73924970e+01,
           7.86403135e+01, 7.98982031e+01, 8.11661660e+01, 8.24442021e+01,
           8.37323115e+01, 8.50304940e+01, 8.63387499e+01, 8.76570789e+01,
           8.89854812e+01, 9.03239567e+01, 9.16725055e+01, 9.30311274e+01,
           9.43998227e+01, 9.57785911e+01, 9.71674328e+01, 9.85663477e+01,
           9.99753358e+01, 1.01394397e+02, 1.02823532e+02, 1.04262740e+02,
           1.05712021e+02, 1.07171375e+02, 1.08640803e+02, 1.10120303e+02,
           1.11609877e+02, 1.13109525e+02, 1.14619245e+02, 1.16139039e+02,
           1.17668906e+02, 1.19208846e+02, 1.20758859e+02, 1.22318946e+02,
           1.23889106e+02, 1.25469339e+02, 1.27059645e+02, 1.28660025e+02,
           1.30270478e+02, 1.31891004e+02, 1.33521603e+02, 1.35162275e+02,
           1.36813021e+02, 1.38473840e+02, 1.40144732e+02, 1.41825698e+02,
           1.43516736e+02, 1.45217848e+02, 1.46929034e+02, 1.48650292e+02,
           1.50381623e+02, 1.52123028e+02, 1.53874506e+02, 1.55636058e+02,
           1.57407682e+02, 1.59189380e+02, 1.60981151e+02, 1.62782995e+02,
           1.64594913e+02, 1.66416903e+02, 1.68248967e+02, 1.70091104e+02,
           1.71943315e+02, 1.73805598e+02, 1.75677955e+02, 1.77560385e+02,
           1.79452889e+02, 1.81355465e+02, 1.83268115e+02, 1.85190838e+02,
           1.87123634e+02, 1.89066504e+02, 1.91019447e+02, 1.92982463e+02,
           1.94955552e+02, 1.96938714e+02, 1.98931950e+02, 2.00935259e+02,
           2.02948641e+02, 2.04972096e+02, 2.07005625e+02, 2.09049227e+02,
           2.11102902e+02, 2.13166650e+02, 2.15240471e+02, 2.17324366e+02,
           2.19418334e+02, 2.21522375e+02, 2.23636490e+02, 2.25760677e+02,
           2.27894938e+02, 2.30039273e+02, 2.32193680e+02, 2.34358161e+02,
           2.36532714e+02, 2.38717341e+02, 2.40912042e+02, 2.43116815e+02,
           2.45331662e+02, 2.47556582e+02, 2.49791575e+02, 2.52036642e+02,
           2.54291782e+02, 2.56556994e+02, 2.58832281e+02, 2.61117640e+02,
           2.63413073e+02, 2.65718579e+02, 2.68034158e+02, 2.70359810e+02,
           2.72695536e+02, 2.75041334e+02, 2.77397206e+02, 2.79763152e+02,
           2.82139170e+02, 2.84525262e+02, 2.86921427e+02, 2.89327665e+02,
           2.91743977e+02, 2.94170361e+02, 2.96606819e+02, 2.99053350e+02,
           3.01509955e+02, 3.03976632e+02, 3.06453383e+02, 3.08940207e+02,
           3.11437104e+02, 3.13944075e+02, 3.16461119e+02, 3.18988236e+02,
           3.21525426e+02, 3.24072689e+02, 3.26630026e+02, 3.29197436e+02,
           3.31774919e+02, 3.34362476e+02, 3.36960105e+02, 3.39567808e+02,
           3.42185584e+02, 3.44813433e+02, 3.47451356e+02, 3.50099352e+02,
           3.52757421e+02, 3.55425563e+02, 3.58103779e+02, 3.60792067e+02,
           3.63490429e+02, 3.66198864e+02, 3.68917373e+02, 3.71645955e+02,
           3.74384609e+02, 3.77133338e+02, 3.79892139e+02, 3.82661013e+02,
           3.85439961e+02, 3.88228982e+02, 3.91028077e+02, 3.93837244e+02,
           3.96656485e+02, 3.99485799e+02, 4.02325186e+02, 4.05174647e+02,
           4.08034180e+02, 4.10903787e+02, 4.13783467e+02, 4.16673221e+02,
           4.19573047e+02, 4.22482947e+02, 4.25402920e+02, 4.28332967e+02,
           4.31273086e+02, 4.34223279e+02, 4.37183545e+02, 4.40153884e+02,
           4.43134297e+02, 4.46124782e+02, 4.49125341e+02, 4.52135973e+02,
           4.55156679e+02, 4.58187457e+02, 4.61228309e+02, 4.64279234e+02,
           4.67340233e+02, 4.70411304e+02, 4.73492449e+02, 4.76583667e+02,
           4.79684958e+02, 4.82796323e+02, 4.85917761e+02, 4.89049272e+02,
           4.92190856e+02, 4.95342513e+02, 4.98504244e+02, 5.01676048e+02,
           5.04857925e+02, 5.08049875e+02, 5.11251899e+02, 5.14463996e+02,
           5.17686166e+02, 5.20918409e+02, 5.24160726e+02, 5.27413115e+02,
           5.30675578e+02, 5.33948115e+02, 5.37230724e+02, 5.40523407e+02,
           5.43826163e+02, 5.47138992e+02, 5.50461894e+02, 5.53794870e+02,
           5.57137919e+02, 5.60491041e+02, 5.63854236e+02, 5.67227505e+02,
           5.70610847e+02, 5.74004262e+02, 5.77407750e+02, 5.80821311e+02,
           5.84244946e+02, 5.87678654e+02, 5.91122435e+02, 5.94576290e+02,
           5.98040217e+02, 6.01514218e+02, 6.04998292e+02, 6.08492440e+02,
           6.11996660e+02, 6.15510954e+02, 6.19035321e+02, 6.22569761e+02,
           6.26114275e+02, 6.29668862e+02, 6.33233522e+02, 6.36808255e+02,
           6.40393061e+02, 6.43987941e+02, 6.47592894e+02, 6.51207920e+02,
           6.54833019e+02, 6.58468192e+02, 6.62113438e+02, 6.65768757e+02,
           6.69434149e+02, 6.73109615e+02, 6.76795154e+02, 6.80490766e+02,
           6.84196451e+02, 6.87912209e+02, 6.91638041e+02, 6.95373946e+02,
           6.99119924e+02, 7.02875976e+02, 7.06642100e+02, 7.10418298e+02,
           7.14204569e+02, 7.18000914e+02, 7.21807331e+02, 7.25623822e+02,
           7.29450386e+02, 7.33287023e+02, 7.37133734e+02, 7.40990517e+02,
           7.44857374e+02, 7.48734305e+02, 7.52621308e+02, 7.56518385e+02,
           7.60425535e+02, 7.64342758e+02, 7.68270054e+02, 7.72207424e+02,
           7.76154867e+02, 7.80112383e+02, 7.84079972e+02, 7.88057634e+02,
           7.92045370e+02, 7.96043179e+02, 8.00051061e+02, 8.04069017e+02,
           8.08097046e+02, 8.12135148e+02, 8.16183323e+02, 8.20241571e+02,
           8.24309893e+02, 8.28388288e+02, 8.32476756e+02, 8.36575297e+02,
           8.40683912e+02, 8.44802599e+02, 8.48931360e+02, 8.53070195e+02,
           8.57219102e+02, 8.61378083e+02, 8.65547137e+02, 8.69726264e+02,
           8.73915464e+02, 8.78114738e+02, 8.82324085e+02, 8.86543505e+02,
           8.90772998e+02, 8.95012565e+02, 8.99262205e+02, 9.03521918e+02,
           9.07791704e+02, 9.12071564e+02, 9.16361496e+02, 9.20661502e+02,
           9.24971582e+02, 9.29291734e+02, 9.33621960e+02, 9.37962259e+02,
           9.42312631e+02, 9.46673076e+02, 9.51043595e+02, 9.55424187e+02,
           9.59814852e+02, 9.64215590e+02, 9.68626402e+02, 9.73047286e+02,
           9.77478244e+02, 9.81919276e+02, 9.86370380e+02, 9.90831558e+02,
           9.95302809e+02, 9.99784133e+02, 1.00427553e+03, 1.00877700e+03,
           1.01328854e+03, 1.01781016e+03, 1.02234185e+03, 1.02688362e+03,
           1.03143545e+03, 1.03599736e+03, 1.04056935e+03, 1.04515140e+03,
           1.04974353e+03, 1.05434574e+03, 1.05895801e+03, 1.06358036e+03,
           1.06821278e+03, 1.07285528e+03, 1.07750785e+03, 1.08217049e+03,
           1.08684321e+03, 1.09152600e+03, 1.09621886e+03, 1.10092179e+03,
           1.10563480e+03, 1.11035788e+03, 1.11509104e+03, 1.11983427e+03,
           1.12458757e+03, 1.12935094e+03, 1.13412439e+03, 1.13890791e+03,
           1.14370151e+03, 1.14850517e+03, 1.15331891e+03, 1.15814273e+03,
           1.16297662e+03, 1.16782058e+03, 1.17267461e+03, 1.17753872e+03,
           1.18241290e+03, 1.18729715e+03, 1.19219148e+03, 1.19709588e+03,
           1.20201035e+03, 1.20693490e+03, 1.21186952e+03, 1.21681421e+03,
           1.22176898e+03, 1.22673382e+03, 1.23170873e+03, 1.23669371e+03,
           1.24168877e+03, 1.24669391e+03, 1.25170911e+03, 1.25673439e+03,
           1.26176974e+03, 1.26681517e+03, 1.27187066e+03, 1.27693624e+03,
           1.28201188e+03, 1.28709760e+03, 1.29219339e+03, 1.29729926e+03,
           1.30241519e+03, 1.30754120e+03, 1.31267729e+03, 1.31782345e+03,
           1.32297968e+03, 1.32814598e+03, 1.33332236e+03, 1.33850881e+03,
           1.34370533e+03, 1.34891193e+03, 1.35412860e+03, 1.35935534e+03])

```python
import matplotlib.pyplot as plt
plt.plot(p,lambdified_expr(p))

plt.title("parabola")
plt.show()
```

```python

```