# [SciPy-user] Coupled ODEs

Nils Wagner nwagner@iam.uni-stuttgart...
Tue Apr 22 12:29:37 CDT 2008

On Tue, 22 Apr 2008 18:00:54 +0100
Colin Gillespie <c.gillespie@ncl.ac.uk> wrote:
> Hi,
>
> How do I solve coupled ODEs using scipy?
>
>For the ODE
>
> dz/dt = z^2
>
> I have
>
> from scipy import *
> def f(t,z):
>    return z**2
> t = [0,1]
> z0 = array([0])
>
> z = integrate.odeint(f, z0, t)
> print z
>
> But how do I handle:
>
> dy/dt = y*z
> dz/dt = z^2+y
>
> Thanks
>
> Colin
>
>
>
> --
> Dr Colin Gillespie
> http://www.mas.ncl.ac.uk/~ncsg3/
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

from scipy import *
from pylab import plot, show
def func(x,t):

tmp = zeros(2,float)
tmp[0] = x[0]*x[1]
tmp[1] = x[1]**2+x[0]
return tmp

x0 = zeros(2,float) # Initial conditions
x0[0] = 0.1
x0[1] = 0.9

t = linspace(0,1.,100)
x = integrate.odeint(func,x0,t)
plot(t,x[:,0],t,x[:,1])
show()

Nils