-
Notifications
You must be signed in to change notification settings - Fork 0
/
Integrate.py
78 lines (49 loc) · 1008 Bytes
/
Integrate.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
#!/usr/bin/env python
# coding: utf-8
# In[67]:
import numpy as np
import matplotlib.pyplot as plt
# In[131]:
def fu(u):
return u
def fv(v):
return v
def dphi_dR(R,z):
q = 0.9
L = 0.2
v = 1
return -((v**2*q**2*R)/(q**2*R**2+z**2) - (L**2)/(R**3))
def dphi_dz(R,z):
q = 0.9
L = 0.2
v = 1
return -((v**2*z)/(R**2*q**2+z**2))
# In[147]:
t0 = 0
tf = 500
u0 = 0
v0 = 1
R0 = 1
z0 = 1
n = 10000001
h = (tf-t0)/(n-1)
t = np.linspace(t0,tf,n)
sol_u = np.zeros([n])
sol_u[0] = u0
sol_v = np.zeros([n])
sol_v[0] = v0
sol_R = np.zeros([n])
sol_R[0] = R0
sol_z = np.zeros([n])
sol_z[0] = z0
# In[148]:
for i in range(1,n):
sol_u[i] = h*dphi_dR(sol_R[i-1],sol_z[i-1]) + sol_u[i-1]
sol_v[i] = h*dphi_dz(sol_R[i-1],sol_z[i-1]) + sol_v[i-1]
sol_R[i] = h*fu(sol_u[i-1]) + sol_R[i-1]
sol_z[i] = h*fv(sol_v[i-1]) + sol_z[i-1]
# In[149]:
plt.plot(sol_R,sol_z, label = "Orbits")
plt.legend()
plt.savefig("o.png")
# In[ ]: