Double clik to put your name(s) here

Instructions

  • Run the code in each cell by holding down the shift key and pushing Return (Enter)
  • DOWNLOAD A COPY OF THIS NOTEBOOK when you are done!

In [1]:
from __future__ import division, print_function
import numpy as np

from ipywidgets import interact

import matplotlib.pyplot as plt

%matplotlib nbagg


/Users/mcraig/anaconda/lib/python2.7/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)

The cell below defines the potential


In [2]:
def potential(x, V0=20.0):
    if x < 0 or x > 1:
        return V0
    else:
        return 0

Double click here to edit, and describe this potential in words


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)

YOU NEED TO ADD THE CODE BELOW TO CALCULATE PSI


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)

The cell below calculates $\psi$ and graphs it

Change the upper and lower energies until you get a valid solution.


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]:
<matplotlib.legend.Legend at 0x1099cd850>