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

SciPy · Function

quad

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.

How it works

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.

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
funccallablePython callable to integrate; it is called with the integration variable and any values supplied through args.
afloatLower integration limit; use -numpy.inf for negative infinity.
bfloatUpper integration limit; use numpy.inf for positive infinity.
argstuple, optionalAdditional positional arguments passed to func.
full_outputint, optionalIf nonzero, return diagnostic information in addition to the integral and error estimate.
epsabsfloat, optionalAbsolute error tolerance.
epsrelfloat, optionalRelative error tolerance.
limitint, optionalMaximum number of subintervals used in the adaptive process.
pointssequence, optionalInterior break points for difficult behavior; not used with weighted integration.
weightstr, optionalWeighting mode for the integrand.
wvarany, optionalAdditional weighting parameter interpreted according to weight.
woptssequence, optionalOptional reusable weighting information.

Returns

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.

Key points

  • quad numerically computes a definite integral of a callable.
  • The bounds may be finite or infinite; use NumPy infinities for unbounded limits.
  • The implementation delegates adaptive quadrature to QUADPACK.
  • Use args to forward fixed values alongside the integration variable.
  • epsabs controls the requested absolute accuracy.
  • epsrel controls the requested relative accuracy.

Example: Integrate a function over a finite interval

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.

When to use it

Finite-interval numerical integration

Compute areas, expectations, or accumulated quantities represented by one-dimensional functions over finite bounds.

Improper integrals

Evaluate integrals whose lower or upper limit is unbounded by using NumPy infinity as a bound.

Difficult interior regions

Handle known singularities or discontinuities by splitting adaptive work at interior points.

Weighted integrals

Integrate supported oscillatory, algebraic, or logarithmic weighted forms through weight and wvar.

Interview questions

QWhat does scipy.integrate.quad return by default?

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.

QHow do epsabs and epsrel affect integration?

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.

QHow are difficult intervals, weighted integrals, and infinite bounds handled?

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

Source: quad. Checked 2026-10-15.