为solve_ivp 传递参数(新的SciPy ODE API) [英] Pass args for solve_ivp (new SciPy ODE API)

查看:20
本文介绍了为solve_ivp 传递参数(新的SciPy ODE API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了使用 SciPy 解决简单的 ODE,我曾经使用 odeint 函数,形式为:

For solving simple ODEs using SciPy, I used to use the odeint function, with form:

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]

要集成的简单函数可以包含以下形式的附加参数:

where a simple function to be integrated could include additional arguments of the form:

def dy_dt(t, y, arg1, arg2):
    # processing code here

在 SciPy 1.0 中,odeodeint 函数似乎已被更新的 solve_ivp 方法取代.

In SciPy 1.0, it seems the ode and odeint funcs have been replaced by a newer solve_ivp method.

scipy.integrate.solve_ivp(fun, t_span, y0, method='RK45', t_eval=None, dense_output=False, events=None, vectorized=False, **options)

然而,这似乎没有提供 args 参数,文档中也没有任何关于实现 args 传递的指示.

However, this doesn't seem to offer an args parameter, nor any indication in the documentation as to implementing the passing of args.

因此,我想知道新 API 是否可以进行 arg 传递,或者这是尚未添加的功能?(如果此功能已被有意删除,对我来说似乎是一种疏忽?)

Therefore, I wonder if arg passing is possible with the new API, or is this a feature that has yet to be added? (It would seem an oversight to me if this features has been intentionally removed?)

参考:https://docs.scipy.org/doc/scipy/reference/integrate.html

推荐答案

新函数似乎没有 args 参数.作为一种解决方法,您可以创建一个包装器,如

It doesn't seem like the new function has an args parameter. As a workaround you can create a wrapper like

def wrapper(t, y):
    orig_func(t,y,hardcoded_args)

并将其传入.

这篇关于为solve_ivp 传递参数(新的SciPy ODE API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆