-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinfinite_well_with_soft_wall_shootings_method.py
88 lines (87 loc) · 2.56 KB
/
infinite_well_with_soft_wall_shootings_method.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import matplotlib.pyplot as plt
import numpy as np
#Shooting method idea and runge kutta implemented
#this method solves an IVP and make sure that the Boundary values are satified, check wiki
tini=0
tfin=1
Nsteps=1000
psi0=0
psip0=1
e={'e1':20}
psid={}
h=abs(tini-tfin)/Nsteps
t=np.linspace(tini,tfin,Nsteps+1)
d=.1
sig=1
def sign(j):
si=sig*j
if si>0:
si=1
elif si<0:
si=-1
return si
def f(x1,x2,a,i1):
if i1 >= (Nsteps/2)-5 and i1 <= (Nsteps/2)+5:
y1=-2*(a-200)*x1
y2=x2
#print("gatcha no it's not gotcha",i1,t[i1])
else:
y1=-(2*a)*x1
y2=x2
return y1,y2
for key in e.keys():
a1=e[key]
print("e:",a1)
psip=np.zeros(Nsteps+1)
psi=np.zeros(Nsteps+1)
psi[0]=psi0
psip[0]=psip0
while abs(psi[Nsteps-1])>=0.0001 or psi[Nsteps-1]==0 :
for i in range(1,Nsteps):
#calculating psip(t)
#calculating psi(t)
k1=h*f(psi[i-1],0,a1,i)[0]
l1=h*f(0,psip[i-1],a1,i)[1]
k2=h*f(psi[i-1]+l1/2,0,a1,i)[0]
l2=h*f(0,psip[i-1]+k1/2,a1,i)[1]
k3=h*f(psi[i-1]+l2/2,0,a1,i)[0]
l3=h*f(0,psip[i-1]+k2/2,a1,i)[1]
k4=h*f(psi[i-1]+l3,0,a1,i)[0]
l4=h*f(0,psip[i-1]+k3,a1,i)[1]
psi[i]=psi[i-1]+1/6*(l1+2*l2+2*l3+l4)
psip[i]=psip[i-1]+1/6*(k1+2*k2+2*k3+k4)
a1=a1+d
#trying to minimize the steps
if sign(psi[Nsteps-1])*psi[Nsteps-1]>=4.5:
d=5
elif sign(psi[Nsteps-1])*psi[Nsteps-1]>=4:
d=4
elif sign(psi[Nsteps-1])*psi[Nsteps-1]>=3:
d=3
elif sign(psi[Nsteps-1])*psi[Nsteps-1]>=2.0:
d=2
elif sign(psi[Nsteps-1])*psi[Nsteps-1]>=1:
d=1
elif sign(psi[Nsteps-1])*psi[Nsteps-1]>=.5 or sign(psi[Nsteps-1])*psi[Nsteps-1]>=.2:
d=.5
elif sign(psi[Nsteps-1])*psi[Nsteps-1]>=.05 or sign(psi[Nsteps-1])*psi[Nsteps-1]>=.02:
d=.1
elif sign(psi[Nsteps-1])*psi[Nsteps-1]>=.01 or sign(psi[Nsteps-1])*psi[Nsteps-1]>=.005:
d=.01
elif sign(psi[Nsteps-1])*psi[Nsteps-1]>=.001:
d=.005
psid[key]=psi
psik=list(psid.keys())
print(a1)
plt.figure(1)
plt.plot(t,psid[psik[0]])
#plt.plot(t,psid[psik[1]])
#plt.plot(t,psid[psik[2]])
#plt.plot(t,psid[psik[3]])
#plt.plot(t,psid[psik[4]])
plt.axvline(x=0)
plt.axhline(y=0)
#plt.legend(loc="upper right")
plt.xlabel('t')
plt.ylabel(r'$\psi$(t)')
plt.show()