import numpy as np import matplotlib.pyplot as plt from scipy import optimize 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.),0]) yt = np.poly1d([-1/2.*g,V0**2*np.sin(Theta*np.pi/180.)/g, 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.), 0]) yt = np.poly1d([-1/2.*g, V0*np.sin(Theta*np.pi/180.), Y0]) root = optimize.fsolve(yt, 2) return xt(root[0]) # 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 = optimize.fsolve(vt, 2) return yt(root[0]) # Question 5 Theta = np.arange(0, 91, 1) #degrees hauteur = [xmax(t, V0, g, Y0) for t in Theta] # Question 6 def xmax2(Theta, V0, g, Y0): return -xmax(Theta, V0, g, Y0) def ymax2(Theta, V0, g, Y0): return -ymax(Theta, V0, g, Y0) args = (V0, g, Y0) hmax = optimize.fmin_bfgs(ymax2, 40, args=args) dmax = optimize.fmin_bfgs(xmax2, 40, args=args) print "Hauteur max pour l'angle", hmax[0] print "Distance max pour l'angle", dmax[0] # Question 8 plt.close() plt.plot(Theta, hauteur, '*') plt.savefig('ymax.png')