Question: I have written code using python in order to find the range of a projectile when fired from different angles as a function. I now

I have written code using python in order to find the range of a projectile when fired from different angles as a function. I now need to find the launch angle for the range to be 20km. I was told to use the function (the one that I input the angle and it gives the range) in a bisection algorithm to find which angle results with a range of 20km with an angular accuracy of 0.1 degrees.

Below is my code for the function:

def theta (ang, C): #Function for range dt = 0.01 r = 20000 V = 700 t = [0] vx = [V*np.cos(ang/180*np.pi)] vy = [V*np.sin(ang/180*np.pi)] x = [0] y = [0]

#Initial position r = C*V**2

#Acceleration Components as lists

ax = [-(r*np.cos(ang/180*np.pi))] ay = [-g-(r*np.sin(ang/180*np.pi))]

#Euler for values

i = 0 while(y[i] >= 0): t.append(t[i]+dt) vx.append(vx[i]+dt*ax[i]) vy.append(vy[i]+dt*ay[i]) x.append(x[i]+dt*vx[i]) y.append(y[i]+dt*vy[i]) vel = np.sqrt(vx[i+1]**2 + vy[i+1]**2) r = C*vel**2 ax.append(-(r*np.cos(ang/180*np.pi))) ay.append(-g-(r*np.sin(ang/180*np.pi))) i = i +1 yval_1, yval_2 = y[-2:]

xval_1, xval_2 = x[-2:] #print(yval_1, yval_2) x_interp = ((0-yval_1)*(xval_2-xval_1))/(yval_2-yval_1) #Interpolation for more accurate values x_interpolated = x_interp + xval_1 plt.plot(x,y) return x_interpolated

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!