Skip to contents

Computes the definite integral of f(x, y) over the rectangle [min_x, max_x] x [min_y, max_y] with the ported Numerics adaptive Simpson's rule in two dimensions (P2 "math extras"): the tensor-product 3x3-point Simpson estimate over the whole domain is compared against the sum of the four quadrant sub-estimates, and the domain is subdivided into quadrants until the two agree to the requested tolerance.

Usage

quadrature_2d(
  f,
  min_x,
  max_x,
  min_y,
  max_y,
  absolute_tolerance = NULL,
  relative_tolerance = NULL,
  min_depth = NULL,
  max_depth = NULL
)

Arguments

f

a function taking two numbers (x, y) and returning one number.

min_x, max_x, min_y, max_y

the bounds of the rectangle. max_x must be above min_x, and max_y above min_y.

absolute_tolerance, relative_tolerance

the convergence tolerances on the difference between the whole-domain and quadrant-subdivided estimates, each between 1e-15 and 1. NULL, the default, leaves the ported integrator's own defaults (1e-8) in force.

min_depth, max_depth

the recursion-depth bounds. NULL, the default, leaves the ported class's own defaults (0 and 100) in force.

Value

the integral, a single number, carrying the same three attributes quadrature() returns: status, function_evaluations, and standard_error.

Examples

quadrature_2d(function(x, y) x + y, min_x = 0, max_x = 1, min_y = 0, max_y = 1)
#> [1] 1
#> attr(,"status")
#> [1] "Success"
#> attr(,"function_evaluations")
#> [1] 25
#> attr(,"standard_error")
#> [1] 0