问题
I am wondering, what are the differences between ODEINT
and solve_ivp
for solving a differential equation. What could be advantages and disadvantages between them?
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
Thank you
回答1:
Well the main difference is the following:
odeint
came first and is uses lsoda from the FORTRAN package odepack to solve ODEs.solve_ivp
is a more general solution that lets use decide which integrator to use to solve ODEs. If you define themethod
param asmethod='LSODA'
then this will use the same integrator asodeint
. Additionally you can choose other methods such as BDF and RK25.
Regarding performance, there is a ticket that indicate that solve_ivp
is slower. This maybe because its written in Python.
https://github.com/scipy/scipy/issues/8257
Check the docs for both of them in 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
来源:https://stackoverflow.com/questions/55152516/differences-between-two-ode-solvers