I have a bit of code I'm struggling with; modelling a cannonball, so far I have answered task one, with the code pasted below, but I can't get my head around task two, so if someone could help me with that, I'll be very grateful!
def f(r, t):
'''Implements differential equation for cannonball from state vector r and time t'''
# Unpack array of the state
x, y, vx, vy = r
# these variables should updated in your code to be the derivatives of
# the x, y positions and the derivative of the x, y velocities.
dx_t, dy_dt, dvx_dt, dvy_dt = 0, 0, 0, 0
# YOUR CODE HERE
# Drag coefficient, projectile radius (m), area (m2) and mass (kg).
kappa = 0.47
r_cb = 0.15
A = math.pi * r_cb ** 2
rho_lead = 11343.
m = mass_cb
# Air density (kg.m-3), acceleration due to gravity (m.s-2).
rho_air = 1.23
g = 9.81
# For convenience, define this constant.
k = 0.5 * kappa * rho_air * A
# Initial speed and launch angle (from the horizontal).
v0 = 200.00
x, y, vx, vy = r
dx_dt = vx
dy_dt = vy
speed = numpy.hypot(vx, vy)
dvx_dt = -k/m * speed * vx
dvy_dt = -k/m * speed * vy - g
return numpy.array([dx_dt, dy_dt, dvx_dt, dvy_dt])
And then this is task 2, the one I'm struggling with: