两个 ODE 求解器之间的差异

Differences between two ODE solvers

我想知道,ODEINTsolve_ivp在解微分方程时有什么区别。它们之间有什么优缺点?

f1 = solve_ivp(f, [0,1], y0) #y0 is the initial point
f2 = odeint(f, y0, [0, 1], args=(a, b)) # a and b are arguments of function f

谢谢

主要区别如下:

  1. odeint 先来,它使用 FORTRAN 包 odepack 中的 lsoda 求解 ODE。
  2. solve_ivp 是一个更通用的解决方案,让用户决定使用哪个积分器来求解 ODE。如果您将 method 参数定义为 method='LSODA',那么这将使用与 odeint 相同的积分器。此外,您还可以选择其他方法,例如 BDFRK25

关于性能,有一张票表明 solve_ivp 较慢。这可能是因为它是用 Python 写的。

https://github.com/scipy/scipy/issues/8257

在 scipy:

中查看他们两个的文档

https://docs.scipy.org/doc/scipy-1.2.1/reference/generated/scipy.integrate.odeint.html https://docs.scipy.org/doc/scipy-1.2.1/reference/generated/scipy.integrate.solve_ivp.html