You can reformulate your system of equations by writing two equations for each value of a
. One way to do it is
from scipy.integrate import odeint
from numpy import array,linspace,tile,empty_like
a = array([-2.0,-1.5,-1.,-0.5])
b = array([-.1,-.1,-.1,-.1])
yinit = tile(array([0.0005,0.2]),a.size)
def deriv(y,_):
dy = empty_like(y)
dy[0::2]=y[1::2]
dy[1::2]=y[::2]*a+b*y[1::2]
return dy
time = linspace(0.0,10.0,100)
y = odeint(deriv,yinit,time)
you will find in y[:,0]
the solution for y
for a=-2
, in y[:,2]
the solution for a=-1.5
, and so on and so forth with y[:,-1]
being the derivative of y
for a=-.5
.
Anyway, if you want to vectorize this to gain speed, you may be interested in a library that converts your python code to c, and then compiles it. I personally use pydelay
because I need to simulate time delays as well, and would recommend it. You don't even have to deal with the c code, the translation is completely automated.