使用python和scipy.integrate.ode在一个循环中求解两个未耦合的ODE [英] solving two uncoupled ODEs within a loop using python and scipy.integrate.ode

查看:82
本文介绍了使用python和scipy.integrate.ode在一个循环中求解两个未耦合的ODE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用scipy.integrate.ode解决两个非常简单的未耦合ODE时遇到问题.例如下面的简单代码:

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)

有趣的是,每个问题都可以在两个不同的循环中完美解决,但是我不明白为什么这会使第二个ODE求解器返回废话.

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.

推荐答案

当我在ipython中运行您的代码时,我得到了:

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`)

显然您必须使用:

ode.set_integrator

同时集成多个问题

这篇关于使用python和scipy.integrate.ode在一个循环中求解两个未耦合的ODE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆