-
Notifications
You must be signed in to change notification settings - Fork 0
/
main3.py
113 lines (103 loc) · 2.11 KB
/
main3.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from solver import *
from math import *
import matplotlib.pyplot as plt
# params
g = 9.81
m = 7
k = 0.01
x0 = 0.0
y0 = 3.0
vx0 = 20.0
vy0 = 20.0
ax0 = 0
ay0=0
t_akhir = 20
t0 = 0
h = 0.001
def Forces(m,x,y,vx,vy,k):
fx = -k * vx * abs(vx)
fy = -k * vy * abs(vy) - m*g
Epot = m * g * h
return (fx,fy,Epot)
t = []
res = []
res2 = []
res3 = []
step = int((t_akhir - t0) / h)
i=0
while (i < step and y0>0):
tm = (i + 1) * h
(rx_next,ry_next,vx_next,vy_next,ax_next,ay_next,Ekin,Epot) = verlet2DNewton(m ,h,x0,y0, vx0, vy0 , ax0, ay0, Forces,k=0.00)
res.append((rx_next,ry_next))
t.append(tm)
x0 = rx_next
y0 = ry_next
vx0 = vx_next
vy0 = vy_next
ax0 = ax_next
ay0 = ay_next
i = i+1
# params
g = 9.81
m = 7
k = 0.01
x0 = 0.0
y0 = 3.0
vx0 = 20.0
vy0 = 20.0
ax0 = 0
ay0=0
t_akhir = 20
t0 = 0
h = 0.001
i=0
while (i < step and y0>0):
tm = (i + 1) * h
(rx_next,ry_next,vx_next,vy_next,ax_next,ay_next,Ekin,Epot) = verlet2DNewton(m ,h,x0,y0, vx0, vy0 , ax0, ay0, Forces,k=0.01)
res2.append((rx_next,ry_next))
t.append(tm)
x0 = rx_next
y0 = ry_next
vx0 = vx_next
vy0 = vy_next
ax0 = ax_next
ay0 = ay_next
# params
g = 9.81
m = 7
k = 0.01
x0 = 0.0
y0 = 3.0
vx0 = 20.0
vy0 = 20.0
ax0 = 0
ay0=0
t_akhir = 20
t0 = 0
h = 0.001
i=0
while (i < step and y0>0):
tm = (i + 1) * h
(rx_next,ry_next,vx_next,vy_next,ax_next,ay_next,Ekin,Epot) = verlet2DNewton(m ,h,x0,y0, vx0, vy0 , ax0, ay0, Forces,k=0.02)
res3.append((rx_next,ry_next))
t.append(tm)
x0 = rx_next
y0 = ry_next
vx0 = vx_next
vy0 = vy_next
ax0 = ax_next
ay0 = ay_next
x_ = [ el[0] for el in res]
y_ = [ el[1] for el in res]
plt.title('trajectory')
plt.plot(x_,y_,color='b', label = 'k = 0.00')
x_ = [ el[0] for el in res2]
y_ = [ el[1] for el in res2]
plt.plot(x_,y_,color='g', label = 'k = 0.01')
x_ = [ el[0] for el in res3]
y_ = [ el[1] for el in res3]
plt.plot(x_,y_,color='r', label = 'k = 0.02')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()