python - secant method rungekutta schrodinger -


so trying use secant method find ground state energy, have tried multiple ways far , of them returning errors. code far :

import numpy np import matplotlib.pyplot plt %matplotlib inline ###first importing modules  me = 9.1094*10**-31 hbar = 1.0546*10**-34 ec = 1.6022*10**-19 ###defining constants need, electron mass, h bar , electron    charge  = 5*10**-11    ###halfwidth of n = 1000 xsteps = (2*a)/1000 xpoints = np.arange(-a,a+xsteps,xsteps)   ###array of calculation points inside ###using a+xsteps ends @ x=a, , not @ x=a-step  def v(x):     if abs(x)<a:         v=0     else:         v=10**15     return v     ###can modified add other variables, should return v=0 steps  def s(r,x,e):      ###where r vector comprised of phi , 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 vector variables     phipoints = []     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])    

that's original code before trying find e match boundary conditions (psi=0 @ x=-a , @ x=a)

i have tried these 2 far , have both failed:

err = 1       ###error variable set tolerance = ec/1000 e1=25*ec e2=50*ec    ###intial guesses energy  #secant method 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 , e2 next iteration         e2 = e3 

and this:

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 set of equations while err > tolerance:     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 , e2 next iteration         e2 = e3 

neither of these have worked, have ideas?


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -