所以我试图使用正割方法找到一个基态能量,但是到目前为止我已经尝试了多种方法,所有这些都返回了错误。 到目前为止我的代码:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
###First importing the modules as always
Me = 9.1094*10**-31
hbar = 1.0546*10**-34
ec = 1.6022*10**-19
###Defining some constants we will need, electron mass, h bar and electron charge
a = 5*10**-11 ###Halfwidth of the well
N = 1000
xsteps = (2*a)/1000
xpoints = np.arange(-a,a+xsteps,xsteps) ###Array of calculation points inside the well
###using a+xsteps so that it ends at x=a, and not at x=a-step
def V(x):
if abs(x)<a:
V=0
else:
V=10**15
return V ###Can be modified to add other variables, for now should simply return V=0 for all steps
def s(r,x,E): ###Where r is a vector comprised of phi and psi
psi=r[0]
phi=r[1]
fpsi=phi ###function of dpsi/dx
fphi=((2*Me)/hbar**2)*(V(x)-E)*psi ###function of dphi/dx
return np.array([fpsi,fphi])
r=np.array([0,1]) ###Initial conditions
def RungeKuttaSchrod1(r,xpoints,E):
psipoints = [] # getting empty arrays ready for the vector variables
phipoints = []
for x in xpoints:
psipoints.append(r[0])
phipoints.append(r[1])
k1 = xsteps*s(r,x,E)
k2 = xsteps*s(r+0.5*k1, x+0.5*xsteps,E)
k3 = xsteps*s(r+0.5*k2, x+0.5*xsteps,E)
k4 = xsteps*s(r+k3, x+xsteps,E)
r = r + (k1 + 2*k2 + 2*k3 + k4)/6
return np.array([psipoints, phipoints])
到目前为止,我已尝试过这两种方法并且都失败了:
err = 1 ###error variable set
tolerance = ec/1000
E1=25*ec
E2=50*ec ###intial guesses for the energy
#Secant method for this set of equations
while err > tolerance:
E3 = E2 - RungeKuttaSchrod1(r,xpoints,E2)*(E2-E1)/(RungeKuttaSchrod1(r,xpoints,E2)-RungeKuttaSchrod1(r,xpoints,E1))
print "current best guess of ground state energy", E3
err = abs(E2-E1)
E1 = E2 #resetting E1 and E2 for the next iteration
E2 = E3
还有这个:
def fphi2(x,psi,E):
fphi2=((2*Me)/hbar**2)*(V(x)-E)*psi
return fphi2
psi = 0 ###initial condition
err = 1.0 ###intialising error variable
#Secant method for this set of equations
while err > tolerance:
for x in xpoints:
E3 = E2 - RungeKuttaFphi(xpoints,psi,E2)*(E2-E1)/(RungeKuttaFphi(xpoints,psi,E2)-RungeKuttaFphi(xpoints,psi,E1))
print "current best guess of ground state energy", E3
err = abs(E2-E1)
E1 = E2 #resetting E1 and E2 for the next iteration
E2 = E3
这些都没有用,有人有什么想法吗?