import matplotlib.pyplot as plt import numpy as np from scipy.integrate import odeint #### Système 2,2 #### # On definit ici le systeme differentiel def syst(y, t, a11, a12, a21, a22) : x1, x2 = y dydt = [a11 * x1 + a12 * x2, a21 * x1 + a22 * x2] return dydt # Matrice A (choisir les coefficients) a11, a12 = -1,0 a21, a22 = 0,-3 # Intervalle de temps sur lequel on trace la solution t = np.linspace(0, 2, 51) # Choix de la condition initiale y0 = [1,2] # On trace x2 en fonction de x1 # plot en temps positif sol = odeint(syst, y0, t, args=(a11, a12, a21, a22)) plt.plot(sol[:, 0], sol[:, 1], 'b') # plot en temps negatif sol = odeint(syst, y0, -t, args=(a11, a12, a21, a22)) plt.plot(sol[:, 0], sol[:, 1], 'b') # Configuration fenetre graphique plt.grid() plt.xlabel('x1') plt.ylabel('x2') plt.axis([-1,1,-1,1]) # Representation des tangentes aux trajectoires g1 = np.linspace(-1,1,15) g2 = np.linspace(-1,1,15) A1, A2 = np.meshgrid(g1,g2) V1,V2 = syst((A1,A2),t, a11, a12, a21, a22) r1 = np.sqrt(1+V1**2) r2 = np.sqrt(1+V2**2) plt.quiver(A1, A2, V1/r1, V2/r2) plt.show() import numpy.linalg as al A = np.array([[-1, 1 , -1], [-4, -5, 4], [-2, -1, 0]]) L = al.eig(A) print(L[0]) #### Système 3,3 #### # Definition du systeme def syst(y, t, a11, a12, a13, a21, a22, a23, a31, a32, a33): x1, x2, x3 = y dydt = [a11*x1+ a12*x2+ a13*x3, a21*x1+ a22*x2+ a23*x3, a31*x1+ a32*x2+ a33*x3] return dydt # Definition de la matrice A a11, a12, a13 = -1, 1 , -1 a21, a22, a23 = -4, -5, 4 a31, a32, a33 = -2, -1, 0 # Condition initiale y0 = [0,5,-5] # Intervalle de temps pour le trace t = np.linspace(0, 10, 501) # Creation de la solution X sol = odeint(syst, y0, t, args=(a11, a12, a13, a21, a22, a23, a31, a32, a33)) # Configuration du trace plt.plot(t, sol[:, 0], 'b-', label='x1(t)') plt.plot(t, sol[:, 1], 'g:', label='x2(t)') plt.plot(t, sol[:, 2], 'r--', label='x3(t)') plt.legend(loc='best') plt.xlabel('t') plt.title(f'[x1(0),x2(0),x3(0)] = [y0[0],y0[1],y0[2]]') plt.grid() plt.show()