def run_trajecotry(time, h, Ma, ms, km, Wh=2): Xe, Ue = get_trim(aircraft, h, Ma, ms, km) fmt = r'Trim: h={:.1f}, Ma={:.1f}, ms={:.1f}, km={:.1f} -> $\alpha$={:.1f}, $\delta_{{PHR}}$={:.1f}, $\delta_{{th}}$={:.1f}' print fmt.format(h, Ma, ms, km, ut.rad_of_deg(Xe[dyn.s_a]), ut.rad_of_deg(Ue[dyn.i_dm]), Ue[dyn.i_dth]) X = NonLinearTraj(aircraft, h, Ma, ms, km, Wh, time) Xlin = LinearTraj(aircraft, h, Ma, ms, km, Wh, time) figure = dyn.plot(time, X) dyn.plot(time, Xlin, figure=figure)
def simu(): time = np.arange(0, 100, 0.1) PLANE.set_mass_and_static_margin(km[1], Ma[1]) va = dynamic.va_of_mach(Ma[1], h[1]) Xtrim, Utrim = dynamic.trim(PLANE, {'va': va, 'h': h[1]}) x = integrate.odeint(dynamic.dyn, Xtrim, time, args=(Utrim, PLANE)) dynamic.plot(time, x) plt.savefig(file + "simu" + format) plt.show()
def plot_traj_trim(aircraft, h, Ma, sm, km): ''' Affichage d'une trajectoire avec un point de trim comme condition initiale ''' aircraft.set_mass_and_static_margin(km, sm) va = dyn.va_of_mach(Ma, h) Xe, Ue = dyn.trim(aircraft, {'va':va, 'h':h, 'gamma':0}) time = np.arange(0., 100, 0.5) X = scipy.integrate.odeint(dyn.dyn, Xe, time, args=(Ue, aircraft)) dyn.plot(time, X)
def trajectoire(M, h, ms, km, P): t = np.arange(0, 100, 0.5) P.set_mass_and_static_margin(km, ms) va = dyn.va_of_mach(M, h, k=1.4, Rs=287.05) param = {'va': va, 'h': h, 'gamma': 0} Xe, Ue = dyn.trim(P, param) X = scipy.integrate.odeint(dyn.dyn, Xe, t, args=(Ue, P)) trace = dyn.plot(t, X) plt.suptitle("Trajectoire de l'avion", fontsize=22) plt.show()
def trajectoire(X, U, P): t = np.linspace(0, 100, 101) sol = odeint(dy.dyn, X, t, (U, P)) dy.plot(sol[:, 0], sol, U=None, figure=None, window_title="Paramètres d'état en fonction de y(mètres)") plt.savefig( 'seance2/param_of_y.png', dpi=120) # sauvegarde du graphe au format png dans le dossier images plt.show() plt.close() dy.plot(t, sol, U=None, figure=None, window_title="Paramètres d'état en fonction du temps(secondes)") plt.suptitle("Paramètres d'état en fonction du temps(secondes)") plt.savefig( 'seance2/param_of_time.png', dpi=120) # sauvegarde du graphe au format png dans le dossier images plt.show() plt.close() plt.axis([0, max(sol[:, 0]) / 1000. + 10., 10.900, 11.100]) plt.plot(sol[:, 0] / 1000., sol[:, 1] / 1000.) plt.grid(True) plt.xlabel("Distance parcourue y (kilomètres) durant 100s") plt.ylabel("Altitude h (kilomètres)") plt.title("Trajectoire d'un " + P.name) plt.text(1, 10, "Comme attendu le mouvenement est rectiligne uniforme") plt.text( 1, 9, "Point de trim : mac = {:.2f}, h = {:.0f}m, ms = {:.1f}".format( mac, h, P.ms)) plt.text(1, 8, "masse = {:.0f}kg".format(P.m)) plt.savefig( 'seance2/trajectoire2.png', dpi=120) # sauvegarde du graphe au format png dans le dossier images plt.show()
def trajectory(XnonLin, XLin): fig = plt.figure() dyn.plot(time, XnonLin, figure=fig) dyn.plot(time, XLin, figure=fig) figDiff = plt.figure() dyn.plot(time, abs(XLin - XnonLin), figure=figDiff) plt.show()
def q3(T, pt_trim1, pt_trim2): _, _, A, B = state(PLANE, pt_trim1) X, U, _, _ = state(PLANE, pt_trim2) add_wind = np.array([0, 0, 0, atan2(Wh, X[2]), 0, 0]) time = np.arange(0, T, 0.1) x = integrate.odeint(dynamic.dyn, X + add_wind, time, args=(U, PLANE)) dynamic.plot(time, x) plt.savefig(file + "otherpoint" + format) plt.show() dU = np.zeros((4, )) dx = integrate.odeint(dynlin, add_wind, time, args=(dU, A, B)) out = np.array([dxi + X for dxi in dx]) for j, Xj in enumerate(out): out[j][0] += out[j][2] * time[j] dynamic.plot(time, out) plt.savefig(file + "badlin" + format) plt.show() dynamic.plot(time, abs(out - x)) plt.savefig(file + "badlindif" + format) plt.show()
def compare_lin(T, pt_trim): X, U, A, B = state(PLANE, pt_trim) time = np.arange(0, T, 0.1) val_p = np.linalg.eigvals(A[2:, 2:]) add_wind = np.array([0, 0, 0, atan2(Wh, X[2]), 0, 0]) x = integrate.odeint(dynamic.dyn, X + add_wind, time, args=(U, PLANE)) dynamic.plot(time, x) plt.savefig(file + "nolin" + str(T) + format) plt.show() dU = np.zeros((4, )) dx = integrate.odeint(dynlin, add_wind, time, args=(dU, A, B)) out = np.array([dxi + X for dxi in dx]) for j, Xj in enumerate(out): out[j][0] += out[j][2] * time[j] dynamic.plot(time, out) plt.savefig(file + "lin" + str(T) + format) plt.show() dynamic.plot(time, abs(out - x)) plt.savefig(file + "dif" + str(T) + format) plt.show() print([mode(val_p[i]) for i in range(len(val_p))])
'''''' '''''' '''''' # question 4 # simule la trajectoire de l'avion sur 100 secondes avion.set_mass_and_static_margin(point_trim[3], point_trim[2]) va_trim = dynamic.va_of_mach(Ma_trim, h_trim) X_trim, U_trim = dynamic.trim(avion, { 'va': va_trim, 'gamm': 0, 'h': h_trim }) time = np.array([i for i in range(1, 100)]) traj = odeint(dynamic.dyn, X_trim, time, args=(U_trim, avion)) fig = plt.figure() dynamic.plot(time, traj, figure=fig) plt.show() '''''' '''''' '''''' # question 5 # calcul des valeurs propres nb2 = 10 h2 = np.linspace(h[0], h[1], nb2) Ma2 = np.linspace(Ma[0], Ma[1], nb2) ms2 = np.linspace(ms[0], ms[1], nb2) km2 = np.linspace(km[0], km[1], nb2) valeurspropres = np.zeros((len(h2), len(Ma2), len(ms2), len(km2), 4), dtype=complex) for lb, l in enumerate(h2):
#calcul du nouveau vecteur d'état intial on a alpha #atan(wh/vae) dalpha = math.atan(2./X[dy.s_va]) Xi=X.copy() Xi[dy.s_a]+=dalpha print("*******************") #X est l'état d'equilibre Xe = X.copy() dXi=np.zeros(6) dXi[dy.s_a]=dalpha def dyn_lin(X,t): Xdot=np.dot(A,X)-np.dot(A,Xe) return Xdot tt=240 # 240s nb_val=tt+1 t = np.linspace(0, tt, nb_val) sol_lin = odeint(dyn_lin, Xi, t) dy.plot(t, sol_lin, U=None, figure=None, window_title="Paramètres d'état en fonction du temps(secondes)") plt.show() print(sol_lin[240,:])
dalpha = math.atan(2. / X[dy.s_va]) Xi = X.copy() Xi[dy.s_a] += dalpha print("*******************") #X est l'état d'equilibre Xe = X.copy() dXi = np.zeros(6) dXi[dy.s_a] = dalpha def dyn_lin(X, t): Xdot = np.dot(A, X) - np.dot(A, Xe) return Xdot tt = 240 # 240s nb_val = tt + 1 t = np.linspace(0, tt, nb_val) sol_lin = odeint(dyn_lin, Xi, t) dy.plot(t, sol_lin, U=None, figure=None, window_title="Paramètres d'état en fonction du temps(secondes)") plt.show() print(sol_lin[240, :])