Scalar initial-value models
Simulate a scalar decay, growth, or other time-dependent process from a known initial value.
SciPy · Function
Integrates first-order ordinary differential-equation systems from an initial state over specified time points. It supports stiff and non-stiff systems and can pass extra arguments or solver/Jacobian options.
odeint advances an initial-value problem for a first-order ODE across the supplied time points. The derivative callback normally receives the current state before time, while tfirst=True switches it to time before state; extra model arguments are passed through args.
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 | Derivative function defining the system; by default it is called as func(y, t, ...), or as func(t, y, ...) when tfirst=True. |
y0 | array_like | Initial condition for the state. |
t | array_like | Sequence of time points at which to compute the solution. |
args | tuple, optional | Tuple of extra arguments passed to func. |
Dfun | callable, optional | Callable returning the Jacobian of func with respect to y. |
col_deriv | bool, optional | Whether derivatives in Dfun are arranged down columns. |
full_output | bool, optional | Whether to return the solver's diagnostic information. |
ml, mu | int, optional | Lower and upper Jacobian bandwidths for banded systems. |
rtol, atol | array_like or float, optional | Relative and absolute error tolerances. |
tcrit | array_like, optional | Critical points that must not be crossed. |
h0, hmax, hmin | float, optional | Initial, maximum, and minimum integration step sizes. |
ixpr, mxstep, mxhnil, mxordn, mxords, printmessg | int or bool, optional | Controls diagnostic printing and limits on steps, warnings, and method orders. |
A solution array with one row for each requested time point; when full_output is true, diagnostic information is returned as well.
import numpy as np
from scipy.integrate import odeint
def decay(y, t, rate):
return -rate * y
t = np.linspace(0, 5, 51)
solution = odeint(decay, y0=1.0, t=t, args=(0.5,))
print(solution[-1, 0])Integrates exponential decay from an initial value of 1 over the requested time points.
Simulate a scalar decay, growth, or other time-dependent process from a known initial value.
Evolve several interacting quantities whose derivatives depend on the full state vector.
Provide a Jacobian and band structure when the model has exploitable derivative structure.
odeint solves an initial-value problem for a first-order system, using the supplied initial state and requested time points. It supports both stiff and non-stiff systems.
Follow-up: How can the callback argument order be changed? Set tfirst=True so the callback receives time before state; otherwise the default order is state before time.
func is the derivative callback, y0 is the initial state, and t contains the time points where the solution is requested. Additional constants for func are supplied through args.
Follow-up: What must the callback return? It must return the derivative of the current state, with dimensions compatible with y0.
Dfun supplies the Jacobian of the derivative with respect to the state. col_deriv controls whether that Jacobian is arranged with derivatives down columns, and full_output requests diagnostic information.
Follow-up: When are ml and mu useful? They describe lower and upper Jacobian bandwidths for banded systems, allowing the solver to exploit that structure.
scipy.integrate.solve_ivpscipy.integrate.odescipy.integrate.quad