Pass args for solve_ivp (new SciPy ODE API)

后端 未结 6 1570
野性不改
野性不改 2020-12-15 20:08

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_         


        
6条回答
  •  太阳男子
    2020-12-15 20:45

    According to Javier-Acuna's ultra-brief, ultra-useful answer, the feature that you (as well as I) desire has recently been added. This was announced on Github by none other than the great Warren Weckesser (See his Github, StackOverflow) himself. Anyway, jokes aside the docstring of solve_ivp has an example using it in for the `Lotka-Volterra equations

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

    So, just include args as a tuple. In your case

    args = (arg1, arg2)
    

    Please don't use my answer unless your scipy version >= 1.4 . There is no args parameter in solve_ivp for versions below it. I have personally experienced my answer failing for version 1.2.1.

    The implementation by zahabaz would probably still work fine in case your scipy version < 1.4

提交回复
热议问题