! pip install numba

# Start writing code here...
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import ode
from scipy.optimize import minimize, shgo
from numpy import diff
from numba import jit
import math

# Creating a function equivalent to ode45 in Matlab
def ode45(f,tint,y0,rtol=1e-9, method='adam', step_count=200):
# bdf (stiff) vs adam (non-stiff)
r = ode(f).set_integrator('zvode', method=method,rtol=rtol)
r.set_initial_value(y0, tint[0])
dt=(tint[1]-tint[0]) / step_count
t1 = tint[1]
# include the initial values
tt=[tint[0]]
rr=[y0]
while r.successful() and r.t < t1:
tt.append(r.t+dt)
rr.append(np.real(r.integrate(r.t+dt)))
return tt,rr

loc = ("/work/UsainBolt.csv")
UB = pd.read_csv(loc, index_col=None, header='infer')
print(UB)
colone = UB['Position'].tolist()
coltwo = UB['Time2009'].tolist()
colthree = UB['Time2008'].tolist()
time = UB['Time2009'].tolist()
time.pop(0)
V2009 = diff(colone)/diff(coltwo)
V2008 = diff(colone)/diff(colthree)
print(V2009)

def running(t, v, P, k):
vdot = []
vdot.append(P-k*v)
return vdot
#I chose P=6 and K=0.5 because I know for running, human maximum acceleration is around 5-6m/s^2
#also, the maximum running speed for Bolt is around 12m/s which means when someone reaches 12m/s
#dv/dt = 0, so k should be very close to P/12 and the data seems to fit the model pretty well
tt, rr = ode45(
lambda t, v: running(t, v, 6, 0.5),
[0.1, 11], [0], rtol=1e-6
)
ax = pd.DataFrame(rr, index=tt, columns=['v']).plot(
cmap='jet',
figsize=(9, 4),
xlabel='t'
)
ax
plt.plot(time, V2009, 'o')
plt.plot(time, V2008, 'o')