Finite-interval numerical integration
Compute areas, expectations, or accumulated quantities represented by one-dimensional functions over finite bounds.
SciPy · Function
Numerically computes a definite integral over finite or infinite bounds using QUADPACK. It returns the estimated integral and an absolute-error estimate, with options for tolerances, break points, weighting, diagnostics, and complex-valued functions.
quad adaptively evaluates a callable between two limits, using QUADPACK to approximate its definite integral. It returns the numerical estimate and an absolute-error estimate by default; optional arguments control extra callable arguments, tolerances, subdivision limits, weighting, break points, and complex-valued integration.
scipy.integrate.quad(func, a, b, args=(), full_output=0, epsabs=1.49e-08, epsrel=1.49e-08, limit=50, points=None, weight=None, wvar=None, wopts=None, maxp1=50, limlst=50, complex_func=False)| Name | Type | Description |
|---|---|---|
func | callable | Python callable to integrate; it is called with the integration variable and any values supplied through args. |
a | float | Lower integration limit; use -numpy.inf for negative infinity. |
b | float | Upper integration limit; use numpy.inf for positive infinity. |
args | tuple, optional | Additional positional arguments passed to func. |
full_output | int, optional | If nonzero, return diagnostic information in addition to the integral and error estimate. |
epsabs | float, optional | Absolute error tolerance. |
epsrel | float, optional | Relative error tolerance. |
limit | int, optional | Maximum number of subintervals used in the adaptive process. |
points | sequence, optional | Interior break points for difficult behavior; not used with weighted integration. |
weight | str, optional | Weighting mode for the integrand. |
wvar | any, optional | Additional weighting parameter interpreted according to weight. |
wopts | sequence, optional | Optional reusable weighting information. |
By default, returns a tuple (y, abserr): y is the integral of func from a to b, and abserr estimates the absolute error. With full_output nonzero, diagnostic information and a convergence message are also returned.
import numpy as np
from scipy.integrate import quad
value, error = quad(lambda x: x**2, 0, 1)
print(value) # 0.33333333333333337
Integrates x² over the interval [0, 1] and returns the estimated value together with an absolute-error estimate.
Compute areas, expectations, or accumulated quantities represented by one-dimensional functions over finite bounds.
Evaluate integrals whose lower or upper limit is unbounded by using NumPy infinity as a bound.
Handle known singularities or discontinuities by splitting adaptive work at interior points.
Integrate supported oscillatory, algebraic, or logarithmic weighted forms through weight and wvar.
quad computes a definite integral of func from a to b, possibly over an infinite interval, using QUADPACK. By default it returns the integral estimate and an estimate of absolute error.
Follow-up: How would you integrate a function with an extra parameter? Define func(x, parameter) and pass args=(parameter,). The extra values are forwarded to func after x.
epsabs sets the requested absolute tolerance and epsrel sets the requested relative tolerance. The default values are both 1.49e-08.
Follow-up: What should be considered when tightening tolerances? A stricter tolerance can require more evaluations and may be inappropriate when the function or floating-point arithmetic limits attainable accuracy.
Use points to identify known interior locations where the integrand has difficult behavior, and use weight with wvar for supported weighted integrals. Infinite bounds are represented with -numpy.inf or numpy.inf.
Follow-up: Why might points not be usable with weighted integration? The documented interface treats points and weight as alternative integration strategies, so choose the option matching the integrand's structure.
scipy.integrate.quad_vecscipy.integrate.quadraturescipy.integrate.fixed_quadscipy.integrate.dblquadscipy.integrate.tplquadscipy.integrate.nquad