# dblquad: Double and Triple Integration In pracma: Practical Numerical Math Functions

## Double and Triple Integration

### Description

Numerically evaluate double integral over rectangle.

### Usage

``````dblquad(f, xa, xb, ya, yb, dim = 2, ...,
subdivs = 300, tol = .Machine\$double.eps^0.5)

triplequad(f, xa, xb, ya, yb, za, zb,
subdivs = 300, tol = .Machine\$double.eps^0.5, ...)
``````

### Arguments

 `f` function of two variables, the integrand. `xa, xb` left and right endpoint for first variable. `ya, yb` left and right endpoint for second variable. `za, zb` left and right endpoint for third variable. `dim` which variable to integrate first. `subdivs` number of subdivisions to use. `tol` relative tolerance to use in `integrate`. `...` additional parameters to be passed to the integrand.

### Details

Function `dblquad` applies the internal single variable integration function `integrate` two times, once for each variable.

Function `triplequad` reduces the problem to `dblquad` by first integrating over the innermost variable.

### Value

Numerical scalar, the value of the integral.

`integrate`, `quad2d`, `simpson2d`

### Examples

``````f1 <- function(x, y) x^2 + y^2
dblquad(f1, -1, 1, -1, 1)       #   2.666666667 , i.e. 8/3 . err = 0

f2 <- function(x, y) y*sin(x)+x*cos(y)
dblquad(f2, pi, 2*pi, 0, pi)    #  -9.869604401 , i.e. -pi^2, err = 0

# f3 <- function(x, y) sqrt((1 - (x^2 + y^2)) * (x^2 + y^2 <= 1))
f3 <- function(x, y) sqrt(pmax(0, 1 - (x^2 + y^2)))
dblquad(f3, -1, 1, -1, 1)       #   2.094395124 , i.e. 2/3*pi , err = 2e-8

f4 <- function(x, y, z) y*sin(x)+z*cos(x)
triplequad(f4, 0,pi, 0,1, -1,1) # - 2.0 => -2.220446e-16
``````

pracma documentation built on Nov. 10, 2023, 1:14 a.m.