Python Program Schrodinger Equation Potential
Python Program Schrodinger Equation Potential
−d2ψ(x)dx2+V(x)ψ(x)=Eψ(x)
import numpy as np
import matplotlib.pyplot as plt
def solveTISE(xmin,xmax,h,potFunc,params):
xvec = np.arange(xmin,xmax,h)
Nx = len(xvec)
potFunctVec = potFunc(xvec,params)
mat = -((np.tri(Nx,Nx,1)-np.tri(Nx,Nx,-2)-3.*np.eye(Nx))/h**2-
np.diag(potFunctVec))
print(mat)
eigenValues,eigenVectors = np.linalg.eig(mat)
idx = eigenValues.argsort()[::1]
eigenValues = eigenValues[idx]
eigenVectors = eigenVectors[:,idx]
return eigenValues,eigenVectors,xvec
def doubleWell(x,params):
return np.piecewise(x, [x < 0, x >= 0], [lambda x : params[2]*(x**4 -
params[0]*x**2), lambda x : params[3]*(x**4 - params[1]*x**2)] )
betaValue = 0.01;
hValue = 0.01;
eigEnergy1i, eigFunc1i, xvec1i = solveTISE(-10,10,hValue,doubleWell,[4,4,1,1]);
plt.plot(xvec1i,eigFunc1i[0]);
plt.show()
plt.plot(xvec1i,eigFunc1i[1]);
plt.show()