Skip to content

Instantly share code, notes, and snippets.

@evildmp
Created November 26, 2022 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evildmp/b5ccf5c42ca0c242d85a5e08cd63c8c9 to your computer and use it in GitHub Desktop.
Save evildmp/b5ccf5c42ca0c242d85a5e08cd63c8c9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 26 12:42:00 2022
@author: tommasoprocida
"""
import math
import numpy as np
import matplotlib.pyplot as plt
Cd = 1
p = 1.2
A = 0.8
k = (Cd * p * A)/2
m = 100
g = 9.81
NumPoints = 2000
tmin = 0.0
yvals = np.zeros(NumPoints)
vyvals = np.zeros(NumPoints)
print("This section will explore Baumgartner's approach of the sound barrier.")
print()
gamma = 1.4
R = 8.3145
M = 0.0289645
dt = 0.1
tvals = np.arange(0, 1000, dt)
yvals = np.zeros(len(tvals))
vyvals = np.zeros(len(tvals))
p0 = 1.2
h = 7640
yvals[0] = 39045
v0 = 0
Vs = np.zeros(len(tvals))
for n in range(len(tvals)):
py = p0 * math.exp(-yvals[n]/h)
ky = (Cd * py * A)/2
vyvals[n+1] = vyvals[n] - (dt * (g + ((ky/m) * abs(vyvals[n]) * vyvals[n])))
yvals[n+1] = yvals[n] + (dt * vyvals[n])
tvals[n+1] = tvals[n] + dt
if yvals[n] > 25100:
T = 141.3 + (0.0030 * yvals[n])
Vs[n] = math.sqrt((gamma * R * T)/M)
elif yvals[n] < 11000:
T = 288 - (0.0065 * yvals[n])
Vs[n] = math.sqrt((gamma * R * T)/M)
else:
T = 216.5
Vs[n] = math.sqrt((gamma * R * T)/M)
if yvals[n+1] <= 0:
break
tvals = tvals[:n+1]
yvals = yvals[:n+1]
vyvals = vyvals[:n+1]
Vs = Vs[:n+1]
fig ,(ax1) = plt.subplots(1, figsize = (12,4))
fig . suptitle('Velocity data for Newtonian freefall with varying drag')
ax1.set(xlabel='Time (s)', ylabel='Speed (m/s))', title='Altitude')
ax1.plot(tvals, Vs, 'tab:red', label="Speed of Sound")
ax1.plot(tvals, -vyvals, 'tab:green', label="Speed of Baumgartner")
plt.legend(loc="center right")
plt.show()
maxspeed = -(min(vyvals))
print()
supersonic = []
# list.append() appends the entire argument as a single list item
supersonic.append(np.where(abs(vyvals) >= Vs))
# so now your list contains just one item
# but now you redefine supersonic anyway:
supersonic = np.array(supersonic, dtype=int)*dt
print("The times Baumgartner is travelling at supersonic speeds are:",supersonic, "seconds")
print("A total of 18 seconds")
print("The maximum speed reached by Baumgartner on his descent was", maxspeed, "m/s")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment