# -*- coding: utf-8 -*- import numpy as np import scipy.integrate import matplotlib.pyplot as plt import matplotlib.animation as animation w02 = 10 y0 = np.array([np.pi, 0]) frict = 0.5 # y' = f(y, t) def f(y, t): # y[0] = angle, y[1] = vitesse angulaire # On renvoie : (vitesse, accélération) frottement = - frict * 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') plt.xlabel(r'$\theta$'); plt.ylabel(r"$\theta'$") curves = plt.plot(theta, thetadot) def animate(i): global frict frict = i / float(200) y = scipy.integrate.odeint(f, y0, t) theta, thetadot = y[:, 0], y[:, 1] plt.title('Pendule : diagramme de phase (frict = ' + str(frict) + ')') curves[0].set_data(theta, thetadot) ani = animation.FuncAnimation(fig, animate, interval=10) plt.show()