import numpy as np import matplotlib.pyplot as plt X0 = 0 # m Y0 = 10 # m V0 = 10 # m/s g = 9.8 # m/s^2 # Question 1 Theta = 30. # degrees xt = np.poly1d([ V0*np.cos(Theta*np.pi/180.), X0]) yt = np.poly1d([-1/2.*g, V0*np.sin(Theta*np.pi/180.), Y0]) # Question 2 time = np.arange(0, 2.2, 0.1) plt.plot(xt(time), yt(time), '*') plt.savefig('canon.png') # Question 3 def xmax(Theta, V0, g, Y0): xt = np.poly1d([ V0*np.cos(Theta*np.pi/180.), X0]) yt = np.poly1d([-1/2.*g, V0*np.sin(Theta*np.pi/180.), Y0]) root = max(yt.roots) return xt(root) # Question 4 def ymax(Theta, V0, g, Y0): vt = np.poly1d([ -g, V0*np.sin(Theta*np.pi/180.)]) yt = np.poly1d([-1/2.*g, V0*np.sin(Theta*np.pi/180.), Y0]) root = max(vt.roots) return yt(root) # Question 5 Theta = np.arange(0, 91, 1) #degrees X = [xmax(t, V0, g, Y0) for t in Theta] # Question 6 Y = [ymax(t, V0, g, Y0) for t in Theta] tmaxX = -90 tmaxY = -90 xmax = 0 ymax = 0 for t in range(len(Theta)): if X[t] > xmax: xmax = X[t] tmaxX = Theta[t] for t in range(len(Theta)): if Y[t] > ymax: ymax = Y[t] tmaxY = Theta[t] print "Hauteur max pour l'angle", tmaxY print "Distance max pour l'angle", tmaxX # Question 8 plt.close() plt.plot(Theta, Y, '*') plt.savefig('ymax.png')