Rectangular-domain integration
Evaluate a surface integral over a region with fixed rectangular bounds.
SciPy · Function
Numerically computes a definite double integral of func(y, x), with x integrated from a to b and y bounded by gfun(x) and hfun(x). It returns the integral estimate together with an error estimate.
dblquad numerically evaluates a double integral by integrating func(y, x) with respect to y between gfun(x) and hfun(x), then integrating those results with respect to x from a to b. The boundary functions may instead be constants, and epsabs and epsrel control the inner quadrature tolerance.
scipy.integrate.dblquad(func, a, b, gfun, hfun, args=(), epsabs=1.49e-08, epsrel=1.49e-08)| Name | Type | Description |
|---|---|---|
func | callable | Integrand accepting y first and x second. |
a, b | float | Lower and upper limits for x, with a < b. |
gfun | callable or float | Lower y boundary as a function of x or a constant. |
hfun | callable or float | Upper y boundary as a function of x or a constant. |
args | sequence, optional | Additional positional arguments passed to func. |
epsabs | float, optional | Absolute tolerance for the inner quadrature. |
epsrel | float, optional | Relative tolerance for the inner integrals. |
A tuple containing y, the resultant integral, and abserr, an estimate of the error.
from scipy.integrate import dblquad
value, error = dblquad(
lambda y, x: x * y**2,
0, 2,
lambda x: 0,
lambda x: 1,
)
print(value) # 0.6666666666666666Integrates x·y² over 0 ≤ x ≤ 2 and 0 ≤ y ≤ 1, returning the estimated value and error.
Evaluate a surface integral over a region with fixed rectangular bounds.
Integrate where the lower or upper y boundary changes with x.
Estimate numerical integration error alongside the computed value.
The integrand receives y first and x second: func(y, x). The outer variable x runs from a to b, while y runs from gfun(x) to hfun(x).
Follow-up: How can constant y bounds be supplied? Pass numeric values instead of callables, such as 0 and 1.
gfun and hfun can each be a callable of x that returns a y boundary, or a float representing a constant boundary. This allows regions whose vertical limits vary with x.
Follow-up: What is the role of args? It supplies extra positional values to func in addition to y and x.
The function returns a pair: y, the resultant integral, and abserr, an estimate of the error. epsabs and epsrel set absolute and relative tolerances for the inner one-dimensional integrations.
Follow-up: What accuracy target is documented? dblquad seeks abs(i-result) <= max(epsabs, epsrel*abs(i)) for the inner integral i.
scipy.integrate.quadscipy.integrate.tplquadscipy.integrate.nquad