Finite-interval numerical integration
Compute the area or accumulated quantity represented by a smooth scalar function on a finite interval.
SciPy · Function
Numerically compute a one-dimensional definite integral of a callable over finite or infinite bounds. quad returns the integral estimate and an absolute-error estimate, with options for tolerances, weighting, and diagnostics.
quad numerically evaluates a scalar function over finite or infinite bounds using QUADPACK. It adaptively samples the callable and returns the estimated integral together with an error estimate; optional arguments control tolerances, subdivision limits, weighting, and diagnostic output.
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 | A callable function of one variable to integrate. |
a | float | Lower limit of integration; may be -numpy.inf. |
b | float | Upper limit of integration; may be numpy.inf. |
args | tuple | Extra arguments passed to func. |
full_output | int | Whether to return additional diagnostic information. |
epsabs | float | Absolute error tolerance. |
epsrel | float | Relative error tolerance. |
limit | int | Upper bound on the number of subintervals. |
points | sequence or None | Interior points where integration difficulty or singular behavior occurs. |
weight | str or None | Weighting mode for the integrand. |
wvar | float or tuple | Additional parameter associated with the selected weight. |
wopts | tuple or None | Optional reusable weighting moments. |
By default, a tuple (y, abserr): the estimated integral and an estimate of its absolute error. With full_output enabled, additional diagnostic information is returned.
quad for numerical integration of a scalar function over a one-dimensional interval.(value, error); the first item is the integral estimate.a and b define the lower and upper integration bounds.args.from scipy.integrate import quad
value, error = quad(lambda x: x**2, 0.0, 1.0)
print(value, error)Integrates \(x^2\) over [0, 1] and prints the estimated integral and its absolute-error estimate.
Compute the area or accumulated quantity represented by a smooth scalar function on a finite interval.
Evaluate expectations, normalization constants, or tail integrals whose bounds extend to positive or negative infinity.
Handle oscillatory, algebraic, or logarithmic integration behavior with the function's weighting options.
Inspect internal computation details when validating convergence or investigating accuracy.
scipy.integrate.quad return?quad computes a one-dimensional definite integral from a to b, possibly over an infinite interval. It returns the estimated integral and an estimate of the absolute error.
Follow-up: How would you integrate a function requiring parameters? Pass those parameters through args, while keeping the callable's first argument as the variable of integration.
quad?The first three positional inputs are the callable, the lower bound, and the upper bound. The callable is evaluated numerically over that interval.
Follow-up: What should be used for an infinite upper bound? Use numpy.inf (and -numpy.inf for a negative-infinite lower bound).
epsabs and epsrel specify absolute and relative error tolerances, while limit bounds the number of subintervals used in the adaptive procedure. More specialized behavior is available through weighting and related options.
Follow-up: When would diagnostics be useful? Set full_output to request additional information about the computation.
scipy.integrate.quad_vecscipy.integrate.fixed_quadscipy.integrate.quadraturescipy.integrate.dblquadscipy.integrate.tplquad