Skip to content

Instantly share code, notes, and snippets.

@wjladams
Created January 22, 2022 18:05
Show Gist options
  • Save wjladams/7211f57ee76bd7d2d57e691b9c6cb367 to your computer and use it in GitHub Desktop.
Save wjladams/7211f57ee76bd7d2d57e691b9c6cb367 to your computer and use it in GitHub Desktop.
import numpy as np
def f(p,t,m,vi):
return np.sqrt(2*p*t/m+vi**2)
vi=0 # starts at rest
m = 1000 # in kg
delta_t=0.01
# Peak horsepower at wheel
p = 700 * 747 # 700 hp * 747 conversion to Watts
total_dist = 0.25 * 1609.344
dist = 0
total_time = 0
while dist < total_dist:
vnext = f(p, delta_t, m, vi)
vavg = (vi + vnext)/2
# How much additional distance I traveled in this time period
delta_dist = vavg * delta_t
# Add that to total_distance traveled thuse far
dist = dist + delta_dist
print("Between t="+str(total_time)+" and t="+str(total_time+delta_t)+" we travel to "+str(dist))
# Increment total time
total_time += delta_t
# Set initial velocity to our last one
vi = vnext
print(total_time)
print("Final velocity is "+str(vnext*2.236936)+" mph")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment