Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

integrate.solve_ivp

Numerically integrates an initial-value problem for a system of ordinary differential equations. It supports multiple solver methods, requested output times, dense interpolation, and event detection.

Since
1.0.0

How it works

solve_ivp numerically advances an initial state through a system defined by fun(t, y) over t_span. It can use different integration methods, sample the solution at t_eval, detect event functions, and optionally construct a continuous interpolant.

Syntax

scipy.integrate.solve_ivp(fun, t_span, y0, method='RK45', t_eval=None, dense_output=False, events=None, vectorized=False, args=None, **options)

Parameters

NameTypeDescription
funcallableRight-hand side of the system: the time derivative of the state y at time t; called as fun(t, y).
t_span2-member sequenceTwo-member interval (t0, tf) over which integration is performed.
y0array_likeInitial state, with shape (n,).
methodstring or OdeSolver, optionalIntegration method; defaults to RK45. Supported choices include RK23, DOP853, Radau, BDF, and LSODA.
t_evalarray_like or None, optionalTimes at which to store the computed solution; values must be sorted and within t_span.
dense_outputbool, optionalWhether to compute a continuous solution representation.
eventscallable or list of callables, optionalEvent function or collection of event functions whose zero crossings are tracked.
vectorizedbool, optionalWhether fun is implemented to accept multiple state columns simultaneously.
argstuple, optionalExtra positional arguments passed to fun and event functions.
optionsdict, optionalAdditional solver-specific options, such as tolerances, maximum step, and initial step.

Returns

Bunch object with fields including t, y, sol, t_events, y_events, nfev, njev, nlu, status, message, and success.

Key points

  • solve_ivp numerically integrates an ODE system from a specified initial state.
  • The right-hand-side callable receives scalar time first and the current state array second.
  • t_span defines the start and end of the integration interval.
  • RK45 is the default explicit solver and uses an embedded fourth-order estimate for error control.

Example: Integrate a scalar ODE

import numpy as np
from scipy.integrate import solve_ivp

def rhs(t, y):
    return -y

sol = solve_ivp(rhs, (0.0, 2.0), [1.0], t_eval=np.linspace(0.0, 2.0, 5))
print(sol.t)
print(sol.y[0])

Integrates the scalar equation y′ = −y from t = 0 to 2 and returns values at five requested times.

When to use it

Initial-value simulation

Simulating a dynamical system from known initial conditions.

Controlled output sampling

Computing trajectories at a fixed set of times for analysis or plotting.

Event-driven integration

Stopping or recording integration when a state-dependent condition is reached.

Dense solution evaluation

Obtaining interpolated state values between solver output points.

Interview questions

QWhat problem does solve_ivp solve?

It solves an initial-value problem for a system of ordinary differential equations, with the right-hand side supplied as fun(t, y). The initial state is y0 and integration proceeds from t0 to tf in t_span.

Follow-up: How would you obtain values between accepted solver steps? Set dense_output=True and use the returned sol callable to evaluate the continuous interpolant.

QHow do you choose an integration method?

RK45 is the default method. The page also documents explicit Runge–Kutta methods, implicit methods for stiff problems, and LSODA, which switches between Adams and BDF methods.

Follow-up: When is an implicit method preferable? Use Radau or BDF when the system is stiff; LSODA can automatically switch between nonstiff and stiff modes.

QWhat does solve_ivp return?

The result contains the time points and state values, along with status information such as success, message, number of function evaluations, and event outputs when applicable.

Follow-up: How can terminal events stop integration? Give an event function a terminal attribute so the solver terminates when that event is detected.

  • scipy.integrate.OdeSolver
  • scipy.integrate.RK45
  • scipy.integrate.RK23
  • scipy.integrate.DOP853
  • scipy.integrate.Radau
  • scipy.integrate.BDF
  • scipy.integrate.LSODA

Source: solve_ivp. Checked 2026-10-15.