Differences between two ODE solvers
Asked Answered
I

1

5

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

Incipit answered 13/3, 2019 at 23:9 Comment(0)
T
10

Well the main difference is the following:

  1. odeint came first and is uses lsoda from the FORTRAN package odepack to solve ODEs.
  2. solve_ivp is a more general solution that lets use decide which integrator to use to solve ODEs. If you define the method param as method='LSODA' then this will use the same integrator as odeint. 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

Teddman answered 13/3, 2019 at 23:54 Comment(3)
So, solve_ivp is better to solve the ODEs, but is slower than ODEINT.Incipit
Read this: github.com/scipy/scipy/issues/8257#issuecomment-359182872. I suppose not noticeable for most problems.Teddman
I am getting similar performance differences. solve_ivp with method='LSODA' takes 1.11s. odeint takes 0.21s. Maximum difference between solutions is about 5e-06Fat

© 2022 - 2025 — McMap. All rights reserved.