我遇到使用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求解器返回废话。
答案 0 :(得分:2)
当我在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
同时整合多个问题