Solvers Available in SciPy solve_ivp
The scipy.integrate.solve_ivp function is Python's
primary tool for solving initial value problems for systems of ordinary
differential equations (ODEs). This article provides a clear overview of
the six built-in numerical integration methods available in
solve_ivp, breaking down their underlying algorithms,
performance characteristics, and ideal use cases for both stiff and
non-stiff systems.
Explicit Solvers (For Non-Stiff Problems)
Explicit methods compute the state of a system at a later time from the state of the system at the current time. They are computationally efficient per step but become unstable when applied to stiff ODEs.
1. RK45 (Default)
- Method: Explicit Runge-Kutta method of order 5(4) with the Dormand-Prince pair.
- Best Used For: General-purpose, smooth, non-stiff problems where moderate accuracy is sufficient.
- Details: This is the default solver in
solve_ivp. It adapts the step size automatically by comparing the 4th- and 5th-order solutions to estimate local truncation error. It should be the first solver you try on an unknown problem.
2. RK23
- Method: Explicit Runge-Kutta method of order 3(2) with the Bogacki-Shampine pair.
- Best Used For: Non-stiff problems where low precision is acceptable, or systems with low smoothness requirements.
- Details:
RK23takes smaller steps with lower computational overhead per step compared toRK45. It can be faster thanRK45when low tolerances are requested or when the derivative evaluation is computationally cheap.
3. DOP853
- Method: Explicit Runge-Kutta method of order 8(5)(3) by Dormand and Prince.
- Best Used For: Non-stiff problems that require very high precision.
- Details: Using an 8th-order formula,
DOP853is efficient when tight tolerances (e.g.,rtol < 1e-7) are required. It performs more derivative evaluations per step thanRK45, but compensates by taking significantly larger step sizes for high-accuracy constraints.
Implicit Solvers (For Stiff Problems)
Stiff equations occur when certain components of the solution change much more rapidly than others, requiring explicit methods to take impractically small steps for stability. Implicit solvers evaluate equations at the future time step, requiring system matrix solutions (often using Jacobians) to ensure stability.
4. Radau
- Method: Implicit Runge-Kutta method of the Radau IIA family of order 5.
- Best Used For: Stiff differential equations and differential-algebraic systems.
- Details:
Radauprovides strong numerical stability (it is A-stable and L-stable). It handles severe stiffness well and supports user-provided Jacobians to accelerate convergence during Newton iterations.
5. BDF
- Method: Backward Differentiation Formulas with variable order and variable step size.
- Best Used For: Stiff problems with high-dimensional systems or computationally expensive functions.
- Details: As a linear multistep method,
BDFreuses evaluations from previous steps, requiring fewer function evaluations per step than implicit Runge-Kutta methods likeRadau. It is a reimplementation of the classic modern stiff ODE solver algorithms.
6. LSODA
- Method: Livermore Solver for Ordinary Differential Equations with Automatic method switching.
- Best Used For: Problems where stiffness is unknown beforehand or varies across the integration interval.
- Details:
LSODAwraps the original Fortran solver. It dynamically switches between the explicit Adams method (for non-stiff intervals) and the implicit BDF method (for stiff intervals), providing automated flexibility without manual intervention.
How to Choose a Solver
- Start with
RK45: If the problem is non-stiff and requires standard precision,RK45is usually the fastest and easiest option. - Use
DOP853for High Accuracy: If error tolerances are stringent (rtolandatol\(\le 10^{-7}\)), useDOP853. - Switch to
RadauorBDFifRK45Fails or Runs Extremely Slowly: If integration takes an excessive number of steps, the system is likely stiff. UseRadaufor strong stability orBDFfor large systems. - Use
LSODAfor Mixed or Unknown Behavior: If you are unsure whether your system exhibits stiff behavior at certain intervals,LSODAprovides robust automated switching.