我想知道,求解微分方程的ODEINT
和solve_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
谢谢
嗯,主要区别是:
-
odeint
首先出现,是从fortran package odepack中使用 lsoda 解决odes。 -
solve_ivp
是一种更通用的解决方案,可以使用确定要使用哪个集成符来求解ODE的解决方案。如果将method
参数定义为method='LSODA'
,则将使用与odeint
相同的集成器。此外,您可以选择其他方法,例如 BDF 和 RK25 。
关于性能,有一张票证表明solve_ivp
较慢。这也许是因为它用python写。
https://github.com/scipy/scipy/sissues/8257
在Scipy中检查两个文档:
https://docs.scipy.org/doc/scipy-1.2.1.2.1/reference/generated/scipy.integrate.odeint.html https://docs.scipy.org/doc/scipy-1.2.1/reference/generated/scipy.integrate.solve.solve_ivp.html