[SciPy-user] integrating a system of differential equations

Fabrice Silva silva@lma.cnrs-mrs...
Wed May 27 10:50:36 CDT 2009

Le mercredi 27 mai 2009 à 16:30 +0100, ms a écrit :
> This is quite unclear to me. That is:
> - A single function should calculate the whole system? This is what is
> done of course, with each dy(j)/dt saved in a vector at index j for
> every j-th equation; but I am not sure it is doable in the way ode wants
> it -because I really don't understand how ode wants stuff.

You need to write your system of differential equations as a system of
first-order differential equations. 
if X=[X_1, ..., X_N] is the vector of unknown signals, the function you
have to supply is the function that computes the time derivatives of
these signals.

        def func_ode(X,t):
                dX = np.zeros_like(X)
                for n in xrange(len(X)):
                return dX

then you call the odeint routine giving an initial condition X0 and a
time range TimeVec:
        import scipy.integrate as integrate
        X = integrate.odeint(func_ode, X0, TimeVec)

> - As for the Jacobian, I'm lost.
You do not have to provide the jacobian. The Ode Solver recommends but
does not require it.

Fabrice Silva <silva@lma.cnrs-mrs.fr>

More information about the SciPy-user mailing list