- #1
CrosisBH
- 27
- 4
- Homework Statement
- Recreate the given plot.
- Relevant Equations
- The Shooting Method algorithm.
The book's procedure for the "shooting method"
The point of this program is to compute a wave function and to try and home in on the ground eigenvalue energy, which i should expect pi^2 / 8 = 1.2337...
This is my program (written in python)
Python:
import matplotlib.pyplot as plt
import numpy as np
dx = 0.01
V0 = 1000 #idk units
cutoff = 2.0#number of points of size dx from -1 to 1
N = int(2/dx)
#idk the units on these, natural units i believe.
E = 1
dE = 0.1
#x_axis to make our potential
x_axis = np.arange(-3,3,dx)
#x_axis for our wavefunction
x_axis_wave = np.arange(-1,1,dx)
#actual potential
potential = np.zeros(int(6/dx))#setting up the square well potential
for i in range(0,len(potential)):
if(abs(x_axis[i])<=1):
potential[i] = 0
else:
potential[i] = V0last_diverge = 1
#implementing psi(0) = psi(-1) = 0, which makes the derivitive 0, required for even parity
wavefunction = np.zeros(int(2/dx))
wavefunction[0]=1
wavefunction[int(len(wavefunction)/2)]=1
fig = plt.figure(figsize = (5,5))
#the book has manual dE messing with but i found this to be easier to implement
while(abs(dE)>0.025):
#for reach point the wave function is defined by
for i in range(0,N-1):
#step function for the 2nd derivitive
wavefunction[i+1] = 2*wavefunction[i] - wavefunction[i-1]-2*(E-potential[i])* dx**2 *wavefunction[i]
#divergence check
if(abs(wavefunction[i+1])>cutoff):
break
#plot the wave function and log the data points of interest.
plt.plot(x_axis_wave, wavefunction)
print("ΔE = ", dE, "E = ",f"{E:0.2f}","Ψ(1) = ", f"{wavefunction[i+1]:0.2f}", end="\r")
#updating energy
#updating dE if the signs are different
if wavefunction[i+1]*last_diverge<0:
dE /= -2
E = E+dE
last_diverge = np.sign(wavefunction[i+1])
print("ΔE = ", dE, "E = ",f"{E:0.2f}","Ψ(1) = ", f"{wavefunction[i+1]:0.2f}")
#potential lines
plt.plot([-1,-1],[-100,100], color='black',linestyle=':')
plt.plot([ 1, 1],[-100,100], color='black',linestyle=':')
plt.xlim(-2,2)
plt.ylim(-2,2)
plt.xlabel("x")
plt.ylabel(r"$\psi$")
plt.xticks(np.linspace(-2,2,5))
plt.yticks(np.linspace(-2,2,5))
plt.title("Even-Parity Wave Function Calculation")
plt.show()
The program with the code is that it doesn't want to converge on an energy, it kind goes all over the place until the dE condition is met. The associated "eigenvalue" (if you can even call it that at this point) is 2339.77. This is the closest I've gotten to it. Also the (incomplete) plot.
Which of course doesn't match the original plot at all.