python - 使用 python 和 scipy.integrate.ode 求解循环内的两个非耦合 ODE

标签 python scipy ode

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

 <p></p>

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 求解器返回无意义的结果。

最佳答案

当我在 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

同时整合多个问题

关于python - 使用 python 和 scipy.integrate.ode 求解循环内的两个非耦合 ODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23574146/

相关文章:

python - 在 Python 中优化微分方程中的常数

python - 使用 `set` 计算列表元素

Python curses 从 stdin 读取单个字符会影响 print 语句的输出

python - 来自边缘列表的 Scipy 稀疏矩阵

python - 来自整数列表列表的 Scipy 稀疏矩阵

ode - 无法使用 Scilab 正确求解 ODE

python - cov_type ='HAC' 错误 statsmodels 0.7 IPython 3 笔记本 python 2.7 anaconda mac os x

python - argparse:像帮助字符串一样处理版本字符串

python - n维数据的高斯KDE : leading minor of the array is not positive definite

python - 使用 Python 绘制 ODE、等倾线