The question body:
A skydiver of mass m in a vertical free fall experiences an aerodynamic drag force F=cy'² ('c times y prime square') where y is measured downward from the start of the fall, and y is a function of time (y' denotes the derivative of y w.r.t time). The differential equation describing the fall is:
y''=g-(c/m)y'²
(where g = 9.80665 m/s^2; c = 0.2028 kg/m; m = 80 kg). And y(0)=y'(0)=0 as this is a free fall.
Task: The function must return the time of a fall of x meters, where x is the parameter of the function. The values of g, c and m are given below.
The Runge-Kutta function is defined as follows:
from numpy import *
def runge_kutta_4(F, x0, y0, x, h):
'''
Return y(x) given the following initial value problem:
y' = F(x, y)
y(x0) = y0 # initial conditions
h is the increment of x used in integration
F = [y'[0], y'[1], ..., y'[n-1]]
y = [y[0], y[1], ..., y[n-1]]
'''
X = []
Y = []
X.append(x0)
Y.append(y0)
while x0 < x:
k0 = F(x0, y0)
k1 = F(x0 + h / 2.0, y0 + h / 2.0 * k0)
k2 = F(x0 + h / 2.0, y0 + h / 2 * k1)
k3 = F(x0 + h, y0 + h * k2)
y0 = y0 + h / 6.0 * (k0 + 2 * k1 + 2.0 * k2 + k3)
x0 += h
X.append(x0)
Y.append(y0)
return array(X), array(Y)
And this is what I've done so far:
def prob_1_8(x)
g = 9.80665 # m/s**2
c = 0.2028 # kg/m
m = 80 # kg
def F(x, y):
return array([
y[1],
g - (c / m) * ((y[1]) ** 2)
])
X, Y = runge_kutta_4(F, 0, array([0, 0]), 5000, 1000)
for i in range(len(X)):
if X[i] == 5000:
return Y[i]
However, when I tried to print prob_1_8(5000), the number looks ridiculous and it displayed:
RuntimeWarning: overflow encountered in double_scalars.
According to the answer provided, I should get a value close to 84.8 when x=5000. Can someone help me with this? I don't know what's the problem and how to fix it.