{ } Raw JSON

bundles / scipy latest / scipy / integrate / _quadpack_py / dblquad

function

scipy.integrate._quadpack_py:dblquad

source: /scipy/integrate/_quadpack_py.py :698

Signature

def   dblquad ( func a b gfun hfun args = () epsabs = 1.49e-08 epsrel = 1.49e-08 )

Summary

Compute a double integral.

Extended Summary

Return the double (definite) integral of func(y, x) from x = a..b and y = gfun(x)..hfun(x).

Parameters

func : callable

A Python function or method of at least two variables: y must be the first argument and x the second argument.

a, b : float

The limits of integration in x: a < b

gfun : callable or float

The lower boundary curve in y which is a function taking a single floating point argument (x) and returning a floating point result or a float indicating a constant boundary curve.

hfun : callable or float

The upper boundary curve in y (same requirements as gfun).

args : sequence, optional

Extra arguments to pass to func.

epsabs : float, optional

Absolute tolerance passed directly to the inner 1-D quadrature integration. Default is 1.49e-8. dblquad tries to obtain an accuracy of abs(i-result) <= max(epsabs, epsrel*abs(i)) where i = inner integral of func(y, x) from gfun(x) to hfun(x), and result is the numerical approximation. See epsrel below.

epsrel : float, optional

Relative tolerance of the inner 1-D integrals. Default is 1.49e-8. If epsabs <= 0, epsrel must be greater than both 5e-29 and 50 * (machine epsilon). See epsabs above.

Returns

y : float

The resultant integral.

abserr : float

An estimate of the error.

Notes

For valid results, the integral must converge; behavior for divergent integrals is not guaranteed.

Details of QUADPACK level routines

quad calls routines from the FORTRAN library QUADPACK. This section provides details on the conditions for each routine to be called and a short description of each routine. For each level of integration, qagse is used for finite limits or qagie is used if either limit (or both!) are infinite. The following provides a short description from [1] for each routine.

qagse

is an integrator based on globally adaptive interval subdivision in connection with extrapolation, which will eliminate the effects of integrand singularities of several types. The integration is is performed using a 21-point Gauss-Kronrod quadrature within each subinterval.

qagie

handles integration over infinite intervals. The infinite range is mapped onto a finite interval and subsequently the same strategy as in QAGS is applied.

Array API Standard Support

dblquad has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

====================  ====================  ====================
Library               CPU                   GPU
====================  ====================  ====================
NumPy                 ✅                     n/a                 
CuPy                  n/a                   ⛔                   
PyTorch               ⛔                     ⛔                   
JAX                   ⛔                     ⛔                   
Dask                  ⛔                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

Examples

Compute the double integral of ``x * y**2`` over the box ``x`` ranging from 0 to 2 and ``y`` ranging from 0 to 1. That is, :math:`\int^{x=2}_{x=0} \int^{y=1}_{y=0} x y^2 \,dy \,dx`.
import numpy as np
from scipy import integrate
f = lambda y, x: x*y**2
integrate.dblquad(f, 0, 2, 0, 1)
Calculate :math:`\int^{x=\pi/4}_{x=0} \int^{y=\cos(x)}_{y=\sin(x)} 1 \,dy \,dx`.
f = lambda y, x: 1
integrate.dblquad(f, 0, np.pi/4, np.sin, np.cos)
Calculate :math:`\int^{x=1}_{x=0} \int^{y=2-x}_{y=x} a x y \,dy \,dx` for :math:`a=1, 3`.
f = lambda y, x, a: a*x*y
integrate.dblquad(f, 0, 1, lambda x: x, lambda x: 2-x, args=(1,))
integrate.dblquad(f, 0, 1, lambda x: x, lambda x: 2-x, args=(3,))
Compute the two-dimensional Gaussian Integral, which is the integral of the Gaussian function :math:`f(x,y) = e^{-(x^{2} + y^{2})}`, over :math:`(-\infty,+\infty)`. That is, compute the integral :math:`\iint^{+\infty}_{-\infty} e^{-(x^{2} + y^{2})} \,dy\,dx`.
f = lambda x, y: np.exp(-(x ** 2 + y ** 2))
integrate.dblquad(f, -np.inf, np.inf, -np.inf, np.inf)

See also

fixed_quad

fixed-order Gaussian quadrature

nquad

N-dimensional integrals

quad

single integral

romb

integrator for sampled data

scipy.special

for coefficients and roots of orthogonal polynomials

simpson

integrator for sampled data

tplquad

triple integral

Aliases

  • scipy.integrate.dblquad