The scipy library contains a large number of scientific modules. This is almost a standard library in the sense that it contains all standard numerical algorithms. The full documentation can be found at http://docs.scipy.org/doc/scipy/reference/.
The module that contains the functions for solving differential equation is the scipy.integrate module with the odeint() et ode() functions. We will present only the ode() function which is more complete. Those functions can solve ordinary differential equation :
where y is a numpy array.
Let us look to the following example with
:
from scipy.integrate import ode
def f(t, y):
return -y
r = ode(f).set_integrator('vode')
r.set_initial_value(y=1,t=0)
print r.integrate(1)
print r.t, r.y
Few remarks :
For example : solution of the linearized pendulum equation: , with initial conditions
and
.
from scipy.integrate import ode
from numpy import *
def f(t, Y):
y, yprime=Y
return array([yprime, -y])
r = ode(f).set_integrator('vode')
r.set_initial_value(array([1,0]),0)
print r.integrate(pi)