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: z,y,xz,y,x

  • a,b: The integration limits in xx where a<ba<b. Both have the type float.

  • gfun: A python function or a float representing the lower boundary curve in yy, a function of xx and returns a single floating-point value.

  • hfun: A python function or a float representing the higher boundary curve in yy, a function of xx and returns a single floating-point value.

  • qfun: A python function or a float representing the lower boundary surface in zz, a function of x,yx,y in that order and returns a single floating-point value.

  • rfun: A python function or a float representing the upper boundary surface in zz, a function of x,yx,y in that order and returns a single floating-point value.

  • args: An optional parameter which is a sequence of extra arguments passed to func.

  • epsabs: An optional parameter that is the absolute tolerance passed directly to the inner 1-D quadrature integration. Default is 1.49e81.49e-8.

  • epsrel: An optional parameter that is the relative tolerance of the inner 1-D integrals. Default is 1.49e81.49e-8.

Return value

  • y: The computed double definite integral of func(y,x). It has the type float.

  • abserr: An estimate of the error. It has the type float.

Code

Lets see how to compute the triple intergal of f(z,y,x)=xyz4f(z,y,x) = xyz^4 using the scipy.integrate.tplquad method where xx is ranging from 11 to 22, yy is ranging from 22 to 33, and zz is ranging from 00 to 11.

from scipy import integrate
func = lambda z, y, x: x*y*z**4
print(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 func which takes input in the order z,y,x.

  • Line 3: We use the scipy.integrate.tplquad method that returns the triple (definite) integral of func. The result is then printed.

Note: gfun and hfun are constant boundary curves in yy as a lambda function of x. And qfun and rfun are the boundary surface in zz as a lambda function of y and x.

Free Resources