为了使用 SciPy 求解简单的 ODE,我曾经使用 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):
# processing code here
在 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 参数,文档中也没有任何关于实现 args 传递的指示。
因此,我想知道新 API 是否可以传递 arg,或者这是尚未添加的功能? (如果有意删除此功能,对我来说似乎是一种疏忽?)
引用: https://docs.scipy.org/doc/scipy/reference/integrate.html
最佳答案
最近在scipy's github上出现了类似的问题.他们的解决方案是使用 lambda
:
solve_ivp(fun=lambda t, y: fun(t, y, *args), ...)
他们争辩说,已经有足够的开销让这无关紧要。
关于python - 为 solve_ivp 传递参数(新的 SciPy ODE API),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48245765/