【问题标题】:What is the R equivalent of the solve_ivp() function in Python?Python 中的solve_ivp() 函数的R 等价物是什么?
【发布时间】:2021-02-14 12:18:11
【问题描述】:

我正在将一些代码从 Python 翻译成 R,并且发现很难在每个代码中找到相应的函数。在这种特殊情况下,我遇到问题的代码是:

x_sol_best = solve_ivp(
                    fun=model_covid,
                    y0=x_0_cases,
                    t_span=[t_predictions[0], t_predictions[-1]],
                    t_eval=t_predictions,
                    args=tuple(optimal_params),
                ).y

scipy.integrate.solve_ivpdocumentation,我看到这个函数中使用的默认积分方法是:'RK45'(默认):5(4)阶的显式龙格-库塔法

R 中的哪些包/函数与此等价?

从 R 中 ode 函数的 R documentation 中,我看到有许多 RK 4(5) 方法可用(粘贴在下面) - 但 Python 文档指出 RK45 是 5(4 )...

谁能提供任何澄清? TIA

"rk45ck"    |   Runge-Kutta Cash-Karp, order 4(5)
"rk45f" |   Runge-Kutta-Fehlberg, order 4(5); Octave: ode45, pair=1
"rk45e" |   Runge-Kutta-England, order 4(5)
"rk45dp6"   |   Dormand-Prince, order 4(5), local order 6
"rk45dp7", "ode45"  |   Dormand-Prince 4(5), local order 7

【问题讨论】:

标签: python r scipy ode runge-kutta


【解决方案1】:

根据文档,solve_ivp() 中的默认求解器是 Dormand-Prince。这在deSolve 包的ode() 函数中调用了ode45

x_sol_best = deSolve::ode(
                    y = x_0_cases,
                    times = t_predictions,
                    func = model_covid,
                    parms = c(...), # vector of parameter values
                    method = "ode45"
                )[ , -1] # drop the t column

【讨论】:

  • 谢谢,Simon - Dormand-Prince 和 RK45 是一回事吗?还是我查看了错误的文档?此链接指出默认方法是 RK45 :docs.scipy.org/doc/scipy/reference/generated/…
  • 如果您点击‘RK45’ (default): Explicit Runge-Kutta method of order 5(4) [1]. 中的小[1],它会带您进入[1] J. R. Dormand, P. J. Prince, “A family of embedded Runge-Kutta formulae”, Journal of Computational and Applied Mathematics, Vol. 6, No. 1, pp. 19-26, 1980. 的参考书目
猜你喜欢
  • 2022-10-15
  • 2023-01-17
  • 1970-01-01
  • 2014-01-22
  • 1970-01-01
  • 2021-06-19
  • 2012-12-27
  • 2018-11-13
  • 1970-01-01
相关资源
最近更新 更多