quadrature_2d

quadrature_2d(
    f,
    min_x,
    max_x,
    min_y,
    max_y,
    absolute_tolerance=None,
    relative_tolerance=None,
    min_depth=None,
    max_depth=None,
    max_function_evaluations=None,
    method='adaptive_simpson',
)

Integrate a user-written function of two variables over a rectangle.

Computes the definite integral of f(x, y) over the rectangle [min_x, max_x] x [min_y, max_y] with either the ported adaptive Simpson rule or the globally adaptive Gauss-Kronrod rule added in Numerics 2.2.

Parameters

Name Type Description Default
f callable A function taking two numbers (x, y) and returning one number. required
min_x float The bounds of the rectangle. max_x must be above min_x, and max_y above min_y. required
max_x float The bounds of the rectangle. max_x must be above min_x, and max_y above min_y. required
min_y float The bounds of the rectangle. max_x must be above min_x, and max_y above min_y. required
max_y float The bounds of the rectangle. max_x must be above min_x, and max_y above min_y. required
absolute_tolerance float The convergence tolerances on the difference between the whole-domain and quadrant-subdivided estimates. Each must lie between 1e-15 and 1. Left unset, the ported integrator’s own defaults (1e-8) apply. None
relative_tolerance float The convergence tolerances on the difference between the whole-domain and quadrant-subdivided estimates. Each must lie between 1e-15 and 1. Left unset, the ported integrator’s own defaults (1e-8) apply. None
min_depth int The recursion-depth bounds. Left unset, the ported class’s own defaults (0 and 100) apply. None
max_depth int The recursion-depth bounds. Left unset, the ported class’s own defaults (0 and 100) apply. None
max_function_evaluations int Maximum evaluations of f. Left unset, the selected integrator’s default applies. None
method str "adaptive_simpson" (the default) or "adaptive_gauss_kronrod". 'adaptive_simpson'

Returns

Name Type Description
QuadratureResult The integral, a float carrying the same three fields :func:quadrature returns: status, function_evaluations, and standard_error.

Examples

>>> import corehydropy as ch
>>> round(ch.quadrature_2d(lambda x, y: x + y, 0, 1, 0, 1), 3)
1.0