我正在将一些代码从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_ivp
文档中,我看到该函数中使用的默认集成方法是:'RK45'(默认(:阶为5(4(的显式Runge-Kutta方法
R中的哪些包/函数与此等效?
从R中ode
函数的R文档中,我看到有许多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
根据文档,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