2

I am having problem for solving two very easy uncoupled ODEs using scipy.integrate.ode. For instance this following simple code:

 

from scipy.integrate import ode

def f(t, y, r_r=1.68,mu_ext=0. ,tau_m=0.020, tau_s=0.005, gs= 0.5):
        dmu = (1./tau_s)*(-y[0] + mu_ext + gs*r_r)
        dx = (1./tau_m)*(-y[1] + y[0])
        return [dmu, dx]

t0 = 0.0                #Intial time
y0 = [4.0, 0.0]         #initial condition for x = 0
y1 = [4.0, 1.0]         #inital condition for x = 1

x0m = ode(f)
x0m.set_initial_value(y0, t0)

x1m = ode(f)
x1m.set_initial_value(y1, t0)
t1 = 1.0
dt = 0.0001

x0 = []
x1 = []

t=0

for i in xrange(1000):
        t +=dt
        x0m.integrate(t)
        x0.append(x0m.y)
        x1m.integrate(t)
        x1.append(x1m.y)

Interestingly, each one can be solved perfectly in two different loops but I don't understand why this makes the second ODE solver return nonsense.

farzada
  • 23
  • 2

1 Answers1

2

When I ran your code in ipython I got:

Integrator `vode` can be used to solve only
a single problem at a time. If you want to      
integrate multiple problems, consider using 
a different integrator (see `ode.set_integrator`)

Apparently you have to use:

ode.set_integrator

to integrate multiple problems at the same time

Elias
  • 1,367
  • 11
  • 25
  • 1
    Thanks for quick reply. The documentation of it is very poor! How can I use ode.set_integrator to solve my problem? – farzada May 09 '14 at 21:58
  • It seems it would also work with runge-kutta method, if I set my solver to work with “dopri5”. – farzada May 09 '14 at 22:04
  • 1
    If you look at pg 270 of the documentation: [link](http://docs.scipy.org/doc/scipy/scipy-ref.pdf) it says that the runge-kutta method is the only mode that supports integrating multiple ODEs at the same time. – Elias May 09 '14 at 23:53
  • Looks like the pdf-with-explicit-page-numbers document is gone. [This exists](http://docs.scipy.org/doc/scipy-0.17.1/reference/generated/scipy.integrate.ode.html) but is for v0.17 explicitly. – uhoh Jul 15 '16 at 08:21