-
Notifications
You must be signed in to change notification settings - Fork 0
/
1D_friction_yildiz.py
96 lines (84 loc) · 2.81 KB
/
1D_friction_yildiz.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
import math
import matplotlib.pyplot as plt
print("------------------------------------------------------------------------------------------------------------------------------")
v0 = int(input("Initial Velocity (m/sec) : "))
h0 = int(input("Height (m) : "))
# Variables
p = 1.225
A = 1
Cd = 0.01
k = (1/2)*p*A*Cd
m = 1
g = 9.81
# Terminal Velocity
vt = math.sqrt(m*g/k)
# Flight Times
t = 0
time_step = 0.0001
tmax = (vt/g)*math.atan(v0/vt)
ft = (vt/g)*math.acosh(math.exp(h0*g/(vt**2)))
ft2 = (vt/g)*(math.acosh(math.exp(g*h0/(vt**2) + math.log(abs(math.cosh(math.atan(v0/vt)))))) - math.atan(v0/vt))
# Decimal Range Function
def decimal_range(i, f, inc):
while i < f:
yield i
i += inc
# Velocity & Height Calculations
time = []
velocity = []
height = []
if v0 == 0:
for t in decimal_range(0, ft+time_step, time_step):
t = t
v = vt*math.tanh(t*(-g/vt))
h = h0 - ((vt**2)/g)*math.log(math.cosh(t*-g/vt))
if h >= 0:
time.append(t)
velocity.append(v)
height.append(h)
else:
if v0 < 0:
for t in decimal_range(0, ft2+time_step, time_step):
t = t
v = vt*math.tanh(t*(-g/vt) + math.atanh(v0/vt))
h = h0 + (vt**2/-g)*(math.log(abs(math.cosh(math.atan(v0/vt) - g*t/vt))) - math.log(abs(math.cosh(math.atan(v0/vt)))))
if h >= 0:
time.append(t)
velocity.append(v)
height.append(h)
elif v0 > 0:
for t in decimal_range(0, tmax, time_step):
t = t
v = vt*math.tan(math.atan(v0/vt) - g*t/vt)
h = h0 - (m/k)*math.log((math.cos(math.atan(v0/vt)))/(math.cos(math.atan(v0/vt) - g*t/vt)))
hmax = h
ft0 = (vt/g)*math.acosh(math.exp(hmax*g/(vt**2)))
time.append(t)
velocity.append(v)
height.append(h)
for t in decimal_range(tmax, tmax+ft0+time_step, time_step):
t = t
v = vt*math.tanh((t - tmax)*(-g/vt))
h = hmax - ((vt**2)/g)*math.log(math.cosh((t - tmax)*-g/vt))
if h >= 0:
time.append(t)
velocity.append(v)
height.append(h)
# Creating the S21.dat File
file = open("S21.dat", "w")
for n in range(len(time)):
file.write("{0:0.4f} {1:30.4f} {2:60.4f}\n".format(time[n] , height[n], velocity[n]))
file.close()
# Reading the File
file = open("S21.dat", "r")
f = file.read()
print(f)
# Plotting the data
plt.plot(time, height, "r", label = "Height [m]")
plt.plot(time, velocity, "b", label = "Velocity [m/s]")
plt.xlabel('Time')
plt.title('Height & Velocity vs Time')
plt.legend(loc = 1)
plt.minorticks_on()
plt.grid(b = True, which = 'both')
plt.show()