Finite
Finite
import pandas as pd
import sympy as sp
import matplotlib.pyplot as plt
def newton(f,df,a,max_error,max_iteration):
m=0
for i in range(max_iteration):
b=a-f(a)/df(a)
if f(b)==0:
return b
if b==0 and f(b)==0:
return b
elif b==0:
error=100
else:
error=np.abs((b-m)/b)*100
m=b
a=b
if error<=max_error:
return b
return 'max iter'
def SWS(r,v):
h=r[2]-r[1]
V_mat=np.diag(v)
d2dx=(np.diag(-2*np.ones(len(r)),k=0)+np.diag(np.ones(len(r)-1),k=-1)+np.dia
H=-0.5*d2dx+V_mat
values,vectors=np.linalg.eigh(H)
return values,vectors
In [303… E_trans=[newton(f,df,2,1e-8,30),newton(g,dg,20,1e-8,30),newton(f,df,5,1e-8,30)]
In [304… r=np.arange(-3,3,0.01)
v=np.zeros(len(r))
a1=np.where(r>-0.5)[0][0]
a2=np.where(r>0.5)[0][0]
v[:a1],v[a2:]=vo,vo
sol=SWS(r,v)
E_SWS=sol[0][:3]
plt.figure(figsize=(8,4))
plt.plot(r,sol[1][:,0],'b-',r,sol[1][:,1],'r:',r,sol[1][:,2],'g--')
plt.ylim(-0.150,0.150);plt.grid();plt.title('wavefunction for different bound st
plt.xlim(-1.5,1.5);plt.legend(['$\psi_o$','$\psi_1$','$\psi_2$'])
plt.vlines([-0.5,0.5],-0.2,1,linestyles='dotted');plt.xlabel('a(length)--->');pl
In [305… E=['E1','E2','E3']
dic={'Energy':E,'Root finding solution(eV)':E_trans,'SWE solution(eV)':E_SWS}
print(pd.DataFrame(dic))
In [306… E_value=[]
l1=np.array([-2,-1.5,-1,-0.5])
for i in l1:
r=np.arange(i-2.5,-i+2.5,0.01)
v=np.zeros(len(r))
a1=np.where(r>i)[0][0]
a2=np.where(r>-i)[0][0]
v[:a1],v[a2:]=vo,vo
sol1=SWS(r,v)
E_value.append(sol1[0][:3])
E_value=np.array(E_value)
dic={'well width a ':-2*l1,'E0':E_value[:,0],'E1':E_value[:,1],'E2':E_value[:,2]
print(pd.DataFrame(dic))
well width a E0 E1 E2
0 4.0 0.273134 1.091966 2.454719
1 3.0 0.466964 1.865658 4.189076
2 2.0 0.973479 3.879762 8.670524
3 1.0 3.135705 12.242246 25.842452
In [307… vo=[8,16,24,32]
E_values=[]
for i in vo:
r=np.arange(-3,3,0.01)
v=np.zeros(len(r))
a1=np.where(r>-0.5)[0][0]
a2=np.where(r>0.5)[0][0]
v[:a1],v[a2:]=i,i
sol1=SWS(r,v)
E_values.append(sol1[0][:4])
E_values=np.array(E_values)
dic={'well depth Vo ':vo,'E0':E_values[:,0],'E1':E_values[:,1],'E2':E_values[:,2
print(pd.DataFrame(dic))
well depth Vo E0 E1 E2 E3
0 8 2.120973 7.188300 8.708095 9.057549
1 16 2.651330 9.962630 16.523932 16.813843
2 24 2.942088 11.353683 22.741292 24.752158
3 32 3.135705 12.242246 25.842452 32.697297