In [1]:
from __future__ import division, print_function
import numpy as np
from ipywidgets import interact
import matplotlib.pyplot as plt
%matplotlib nbagg
In [2]:
def potential(x, V0=20.0):
if x < 0 or x > 1:
return V0
else:
return 0
In [3]:
# Smallest position for which we will calculate psi
x_min = -1
# Largest position for which we will calculate psi
x_max = 2
# Number of points
n_points = 1000
# Create a list of all points at which we will calculate psi, and the spacing
# between those points.
all_x, delta_x = np.linspace(x_min, x_max, num=n_points, retstep=True)
In [4]:
def wave_function(E, all_x, delta_x, psi_0=0.0001, dpsi_dx_0=0):
"""
Calculate the wave function at the positions all_x.
Parameters
----------
E : float
Energy to use in calculating psi. Most Energies do *not* lead to physical
solutions.
all_x : numpy array
Positions at which psi should be calculated.
delta_x: float
Spacing between those positions.
psi_0: float, optional
Value of the wave function at the first position.
dpsi_dx_0: float, optional
Value of the derivative of psi at the first position.
Returns
-------
psi: numpy array
Wave function at all positions.
"""
## FILL THIS IN WITH REAL CODE (which will include a loop)
return np.array(psi)
In [11]:
plt.figure(figsize=(12,10))
E_min = 2.0
E_max = 10.0
for E in np.linspace(E_min, E_max, num=7):
plt.plot(all_x, wave_function(E, all_x), label=str(E))
plt.legend(loc='lower left')
Out[11]: