solving two uncoupled ODEs within a loop using python and scipy.integrate.ode

随声附和 提交于 2019-12-02 04:56:09

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/23574146/solving-two-uncoupled-odes-within-a-loop-using-python-and-scipy-integrate-ode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!