【发布时间】:2016-02-03 22:38:44
【问题描述】:
我有以下涉及 ODE 系统的简化伪代码设置,我尝试使用 scipy 的 odeint 解决。
from scipy.integrate import odeint
def diff_func(y, time, parms):
# Do stuff with parms that depends upon y and t.
new_parms = other_funcs(y,time, parms)
# Now calculate derivatives
dy1_dt = dy1_func(y, new_parms)
dy2_dt = dy2_func(y, new_parms)
# Setup up initial conditions
y_0 = [y_1_0, y_2_0]
time = np.linspace(0, 1000, 1000)
parms = list_o_constants
# Solve diffeq
yout, info = odeint(diff_func, y_0, time, args=(parms,), full_output=True)
根据我给它的输入,我可能会导致无意义的结果 - 或崩溃。我已将问题缩小到y 输入偶尔会变为负数,因为其中之一是温度 - 它会导致各种问题。首先它变为负数的原因尚不清楚,可能是稳定性问题。
我已尝试更改 diff 函数以包含如下检查:
def diff_func(y, time, parms):
if y[1] <= 0.1:
y[1] = 0.1
这似乎工作正常,我仍在测试它。但是,我想问一下:这是否会导致问题,以及是否有更好的方法强制 odeint 只允许正输出(即,如果发现负输出则更改步长)。
谢谢!
【问题讨论】:
标签: python python-3.x scipy differential-equations odeint