What is the scipy.integrate.tplquad method?
Overview
SciPy is an open-source library provided by Python dedicated to scientific computation. The scipy.integrate is a sub-package that provides the functionality to solve several integration methods, including Ordinary Differential Equations (ODEs). The scipy.integrate.tplquad method in SciPy is used to solve general-purpose triple integration.
Syntax
scipy.integrate.tplquad(func, a, b, gfun, hfun, qfun, rfun, args=(), epsabs=1.49e-08, epsrel=1.49e-08)
Parameters
-
func: A Python function or method representing a double integral function taking at least two inputs that act as variables to the double integral. It should take inputs in the variable order: -
a,b: The integration limits in where . Both have the typefloat. -
gfun: A python function or afloatrepresenting the lower boundary curve in , a function of and returns a single floating-point value. -
hfun: A python function or afloatrepresenting the higher boundary curve in , a function of and returns a single floating-point value. -
qfun: A python function or afloatrepresenting the lower boundary surface in , a function of in that order and returns a single floating-point value. -
rfun: A python function or afloatrepresenting the upper boundary surface in , a function of in that order and returns a single floating-point value. -
args: An optional parameter which is a sequence of extra arguments passed tofunc. -
epsabs: An optional parameter that is the absolute tolerance passed directly to the inner 1-D quadrature integration. Default is . -
epsrel: An optional parameter that is the relative tolerance of the inner 1-D integrals. Default is .
Return value
-
y: The computed double definite integral offunc(y,x). It has the typefloat. -
abserr: An estimate of the error. It has the typefloat.
Code
Lets see how to compute the triple intergal of using the scipy.integrate.tplquad method where is ranging from to , is ranging from to , and is ranging from to .
from scipy import integratefunc = lambda z, y, x: x*y*z**4print(integrate.tplquad(func, 1, 2, lambda x: 2, lambda x: 3,lambda x, y: 0, lambda x, y: 1))
Explanation
-
Line 2: We write the lambda function
funcwhich takes input in the orderz,y,x. -
Line 3: We use the
scipy.integrate.tplquadmethod that returns the triple (definite) integral offunc. The result is then printed.
Note:
gfunandhfunare constant boundary curves in as a lambda function ofx. Andqfunandrfunare the boundary surface in as a lambda function ofyandx.