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

SciPy · Function

integrate.quad

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.

How it works

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.

Syntax

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)

Parameters

NameTypeDescription
funccallableA callable function of one variable to integrate.
afloatLower limit of integration; may be -numpy.inf.
bfloatUpper limit of integration; may be numpy.inf.
argstupleExtra arguments passed to func.
full_outputintWhether to return additional diagnostic information.
epsabsfloatAbsolute error tolerance.
epsrelfloatRelative error tolerance.
limitintUpper bound on the number of subintervals.
pointssequence or NoneInterior points where integration difficulty or singular behavior occurs.
weightstr or NoneWeighting mode for the integrand.
wvarfloat or tupleAdditional parameter associated with the selected weight.
woptstuple or NoneOptional reusable weighting moments.

Returns

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.

Key points

  • Use quad for numerical integration of a scalar function over a one-dimensional interval.
  • The calculation is backed by the QUADPACK numerical integration library.
  • Unpack the result as (value, error); the first item is the integral estimate.
  • The second returned item estimates the absolute integration error, useful for checking numerical quality.
  • a and b define the lower and upper integration bounds.

Common mistakes

  • Pass a callable that accepts one integration variable; extra fixed arguments belong in args.

Example: Integrate a scalar function

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.

When to use it

Finite-interval numerical integration

Compute the area or accumulated quantity represented by a smooth scalar function on a finite interval.

Improper integrals

Evaluate expectations, normalization constants, or tail integrals whose bounds extend to positive or negative infinity.

Weighted integration

Handle oscillatory, algebraic, or logarithmic integration behavior with the function's weighting options.

Diagnostic integration

Inspect internal computation details when validating convergence or investigating accuracy.

Interview questions

QWhat does 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.

QWhat are the core arguments to 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).

QWhich options control accuracy and computation?

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_vec
  • scipy.integrate.fixed_quad
  • scipy.integrate.quadrature
  • scipy.integrate.dblquad
  • scipy.integrate.tplquad

Source: scipy.integrate.quad — SciPy v1.11.4 Manual. Checked 2026-10-15.