如何在SciPy新API solve_ivp中传递额外参数?
SciPy solve_ivp的参数传递疑问
之前用SciPy求解常微分方程(ODE)时,我一直习惯用scipy.integrate.odeint函数,它的完整调用形式如下:
scipy.integrate.odeint(func, y0, t, args=(), Dfun=None, col_deriv=0, full_output=0, ml=None, mu=None, rtol=None, atol=None, tcrit=None, h0=0.0, hmax=0.0, hmin=0.0, ixpr=0, mxstep=0, mxhnil=0, mxordn=12, mxords=5, printmessg=0)[source]
待积分的函数还能包含额外参数,比如像这样定义:
def dy_dt(t, y, arg1, arg2): # 这里写处理逻辑
不过到了SciPy 1.0版本,ode和odeint似乎被新的solve_ivp方法替代了,它的调用形式是:
scipy.integrate.solve_ivp(fun, t_span, y0, method='RK45', t_eval=None, dense_output=False, events=None, vectorized=False, **options)
我发现这个新方法里好像没有提供args参数,翻了文档也没找到关于参数传递的实现说明。所以我想搞清楚:这个新API到底支不支持参数传递?是功能还没加上,还是被刻意移除了?如果是刻意移除的话,我觉得这是个疏漏。
内容的提问来源于stack exchange,提问作者sharkmas
相关产品推荐
相关产品推荐

