# -*- coding: utf-8 -*- import numpy as np import scipy.integrate import matplotlib.pyplot as plt w02 = 10 y0 = np.array([np.pi, 0]) # y' = f(y, t) def f(y, t): # y[0] = angle, y[1] = vitesse angulaire # On renvoie : (vitesse, accélération) frottement = - .5 * y[1] return np.array([y[1], -w02 * np.sin(y[0]) + frottement]) t = np.linspace(0, 100, 10000) y = scipy.integrate.odeint(f, y0, t) theta, thetadot = y[:, 0], y[:, 1] fig = plt.figure() ax = fig.add_subplot(111, autoscale_on=False, xlim=(-5, 5), ylim=(-5, 5)) ax.grid() plt.title('Pendule : diagramme de phase') # Le mode mathématique LaTeX est reconnu ($...$). # Astuce Python : r'...' pour faire une chaîne de caractères où les \ # ne sont pas des caractères d'échappement : r'$\theta$ == '$\\theta$' plt.xlabel(r'$\theta$') plt.ylabel(r"$\theta'$") # On n'utilise pas t, mais on trace theta et theta' l'un en fonction # de l'autre. plt.plot(theta, thetadot) plt.show()