import numpy # Numerical library
import pylab # Plotting routines
from scipy.integrate import odeint # ODE integration
# Integrate this system of differential equations
# du/dt = v
# dv/dt = -u
# Our choice of representation: array x contains [u, v]
def f(x, t):
# Compute right hand side of ODE system
return [x[1], -x[0]]
# Time runs from 0 to 10 in 0.1 increments
t = numpy.arange(0.0, 10, 0.1)
# Starting from u=0.0 and v=1.0, integrate over time
y = odeint(f, [0.0, 1.0], t)
# y is now a 2-dimentional array,
# column zero contains u values for all
# times in t, column one contains v
# Plot the u values as a function of time
pylab.plot(t, y[:,0])
pylab.show()