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

查看:333
本文介绍了传递args forsolve_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中,似乎 ode odeint 函数已被更新的 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)

并将其传递.

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

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