# -*- coding: utf-8 -*- from numpy import sin, cos, pi, array import numpy as np import scipy.integrate import matplotlib.pyplot as plt import matplotlib.animation as animation w02 = 10 y0 = np.array([np.pi / 2.0, 0]) # angle, vitesse def f(y, t): # y[0] = angle, y[1] = vitesse angulaire # On renvoie : (vitesse, accélération) return np.array([y[1], -w02 * np.sin(y[0])]) 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=(-1.5, 1.5), ylim=(-1.5, .5)) ax.grid() plt.title('Pendule') plt.xlabel('x'); plt.ylabel('y') pendules = plt.plot((0, sin(y0[0])), (0, -cos(y0[0])), 'o-') def animate(i): angle = theta[i] x = (0, sin(angle)) y = (0, -cos(angle)) pendules[0].set_data(x, y) anim = animation.FuncAnimation(fig, animate, interval=10) # Décommenter pour enregistrer sous forme de vidéo: #anim.save('pendule_anim_simple.mp4', writer='avconv', fps=30) # En cas de problème avec writer, essayer writer='mencoder' plt.show()