Initial-value simulation
Simulate decay, growth, motion, or other state evolution described by first-order equations.
SciPy · Function
Integrates first-order ODE systems from an initial condition across requested time points, handling stiff and non-stiff problems. The derivative callback may use either (y, t, ...) or (t, y, ...) argument order.
odeint advances an initial state through a sequence of time points by solving a first-order ODE system. The derivative callback can receive arguments in either traditional (y, t, ...) order or, with tfirst=True, (t, y, ...); optional Jacobian, tolerance, step-control, and diagnostic settings customize the integration.
scipy.integrate.odeint(func, y0, t, args=(), Dfun=None, col_deriv=0, full_output=0, ml=None, mu=None, rtol=None, atol=None, tcrit=None, h0=0.0, hmax=0.0, hmin=0.0, ixpr=0, mxstep=0, mxhnil=0, mxordn=12, mxords=5, printmessg=0, tfirst=False)| Name | Type | Description |
|---|---|---|
func | callable | Callable computing the derivative; signature func(y, t, ...) or func(t, y, ...) when tfirst=True. |
y0 | array | Initial condition for y. |
t | array | Time points at which to solve for y. |
args | tuple, optional | Extra arguments passed to func. |
Dfun | callable, optional | Jacobian of func. |
col_deriv | bool, optional | Whether Jacobian derivatives are across rows or columns. |
full_output | bool, optional | Whether to return the diagnostic infodict. |
ml, mu | int, optional | Lower and upper bandwidths of the Jacobian. |
rtol, atol | array_like, optional | Relative and absolute error tolerances. |
tcrit | array_like, optional | Critical points where integration should not step past. |
h0, hmax, hmin | float, optional | Initial, maximum, and minimum step sizes. |
ixpr, mxstep, mxhnil, mxordn, mxords, printmessg | int or bool, optional | Diagnostic and solver-control options. |
An array containing the solution at each requested time; with full_output=True, also returns an infodict of integration diagnostics.
import numpy as np
from scipy.integrate import odeint
def decay(y, t, rate):
return -rate * y
t = np.linspace(0, 4, 9)
solution = odeint(decay, y0=[1.0], t=t, args=(0.5,))
print(solution[:, 0])Integrates exponential decay from the initial value 1.0 at the requested time points.
Simulate decay, growth, motion, or other state evolution described by first-order equations.
Integrate systems whose numerical behavior may be stiff or non-stiff.
Supply a Jacobian and bandwidth information for structured systems.
Inspect solver progress and diagnostics during numerical integration.
odeint solves an initial-value problem for first-order ODE systems, including stiff and non-stiff cases. It evaluates the derivative callback at the supplied time points and returns the state at each point.
Follow-up: How can the callback use the conventional argument order? Set tfirst=True so odeint calls it as func(t, y, ...), and apply the same convention to Dfun.
func computes the derivative, y0 supplies the initial state, and t specifies the sequence of times where the solution is requested. Extra fixed inputs go through args as a tuple.
Follow-up: How would you pass two constants? Define func(y, t, a, b) and call odeint(func, y0, t, args=(a, b)).
Dfun supplies the Jacobian of the derivative function, while ml and mu describe lower and upper Jacobian bandwidths. These options can provide solver information for banded systems.
Follow-up: What diagnostic output is available? Use full_output=True to obtain an infodict alongside the computed solution.
scipy.integrate.solve_ivpscipy.integrate.odescipy.integrate