我在使用 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/