python - 为 solve_ivp 传递参数(新的 SciPy ODE API)

标签 python numpy scipy ode odeint

为了使用 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 中,odeodeint 函数似乎已被更新的 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/

相关文章:

python - Pip 安装 Django Windows 10

python - 计算多个数据点的多元正态密度

python - python scipy 中样条线与平面的相交

python - 在 Python 中加载大型 JSON 列表的最佳方式是什么?

python - Pandas 根据索引值分配标签

python - 二维矩阵 : Finding and deleting columns that are subsets of other columns

python - 粘性 cumsum/cumprod numpy

python - 如何沿批量维度广播 numpy 索引?

python - 用距点的距离填充numpy数组的最快方法

带有下划线前缀的python导入模块