In Project 3.5, one needs to calculate dot products. We can do this with np.dot(a, b), where a and b are vectors of any length. For instance, assuming as in Program 3.8 that Y is a 2x3 ndarray, with Y[0]=pos vec and Y[1]= vel vec, then the work done by the drag force in one step, dW, can be calculated as
from numpy.linalg import norm
..................
Y1 = ode.RK4(baseball, Y0, t, h)
v = Y0[1]
dr = Y1[0]-Y0[0]
dW = -b2*norm(v)*np.dot(v, dr) # -b2*|v|*(v.dr)
Y0 = Y1 # reseed
In the above, "norm" function returns the magnitude of a vector, which is the same as np.sqrt(np.dot(v,v)). We can also use vp.mag or vp.dot as well; one just has to make sure to convert the arguments to a vp.vector, limited to 3D vectors of course.