import numpy as np import matplotlib.pyplot as plt from scipy.optimize import root from scipy.integrate import odeint, simps fig, axs = plt.subplots(5, 1, figsize=(8, 30)) #question (b) and (c) feven1=lambda z: np.tan(z) feven2=lambda z: np.sqrt((z0/z)**2.0-1.0) feven=lambda z: np.tan(z)-np.sqrt((z0/z)**2.0-1.0) fodd1=lambda z: 1.0/np.tan(z) fodd2=lambda z: -np.sqrt((z0/z)**2.0-1.0) fodd=lambda z: 1.0/np.tan(z)+np.sqrt((z0/z)**2.0-1.0) a=1.0 V0=20.0 m,hcut=1.0,1.0 z0=(a/2*hcut)*np.sqrt(2.0*m*V0) z=np.linspace(1e-4,z0,1000,endpoint=False) axs[0].plot(z,feven1(z),z,feven2(z)) axs[0].set_ylim(-10,10) axs[0].grid() #evenRootGuess=eval(input("Enter guess roots(z) for even parity (as list): ")) evenRootGuess=[1.2] axs[1].plot(z,fodd1(z),z,fodd2(z)) axs[1].set_ylim(-10,10) axs[1].grid() #oddRootGuess=eval(input("Enter guess roots(z) for odd parity (as list): ")) oddRootGuess=[2.3] evenRoots=root(feven,evenRootGuess).x oddRoots=root(fodd,oddRootGuess).x #question (d) and (e) zRoots=np.sort(np.concatenate((evenRoots,oddRoots))) eigenEnergies=(zRoots*hcut*2/a)**2/(2*m)-V0 print(eigenEnergies) def V(x): return 0.0 if x<0 else -V0 if x