【问题标题】:solving two uncoupled ODEs within a loop using python and scipy.integrate.ode使用 python 和 scipy.integrate.ode 在一个循环中求解两个非耦合 ODE
【发布时间】:2014-06-27 18:09:12
【问题描述】:

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

 

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 求解器返回废话。

【问题讨论】:

    标签: python scipy ode


    【解决方案1】:

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

    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
    

    同时整合多个问题

    【讨论】:

    • 感谢您的快速回复。它的文档很差!如何使用 ode.set_integrator 解决我的问题?
    • 如果我将求解器设置为使用“dopri5”,它似乎也适用于 runge-kutta 方法。
    • 如果您查看文档的第 270 页:link 它说 runge-kutta 方法是唯一支持同时集成多个 ODE 的模式。
    • 看起来 pdf-with-explicit-page-numbers 文档不见了。 This exists 但明确适用于 v0.17。
    猜你喜欢
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多