SciPy is an open-source library provided by Python that is dedicated to scientific computation.
scipy.integrate
is a sub-package in SciPy that provides the functionality to solve several integration methods, including Ordinary Differential Equations (ODEs).
We can use the scipy.integrate.dblquad
method in SciPy to solve general-purpose double integration.
scipy.integrate.dblquad(func, a, b, gfun, hfun, args=(), epsabs=1.49e-08, epsrel=1.49e-08)
func
: This is a Python function or method that represents a double integral function. It takes at least two inputs that acts as variables to the double integral. Given the variables and , it takes as the first argument, and as the second argument.
a,b
: These are the integration limits in where . Both have the type float
.
gfun
: This is a Python function or float
that represents the lower boundary curve in , which is a function of . It returns a single floating-point value.
hfun
: This is a Python function or float
that represents the higher boundary curve in , which is a function of . It returns a single floating-point value.
args
: This is an optional parameter that is a sequence of extra arguments passed to func
.
epsabs
: This is an optional parameter that is the absolute tolerance passed directly to the inner 1-D quadrature integration. Its default is .
epsrel
: This is an optional parameter that is the relative tolerance of the inner 1-D integrals. Its default is .
y
: It is the computed double definite integral of func(y,x)
. It has the type float
.
abserr
: It is an estimate of the error. It has the type float
.
Let’s see how to compute the double intergal of using the scipy.integrate.dblquad
method, where ranges from to , and ranges from to .
from scipy import integratefunc = lambda y, x: x*y**4print(integrate.dblquad(func, 0, 2, lambda x: 0, lambda x: 1))
integrate
from scipy
.Line 2: We write the lambda function func
. It takes two inputs where y
is the first argument and x
is the second argument.
Line 3: We use the scipy.integrate.dblquad
method. It returns the double (definite) integral of func
over the region, where is from to and is from to .
Note: We write the constant boundary curve for as a lambda function of