Use `hcubature` for multidimensional integration
masterThe hcubature function computes the n-dimensional integral of a function f(x) over a hypercube defined by the corners a and b. It uses an h-adaptive algorithm that subdivides the integration volume until the estimated error meets the requested tolerances.
Key Requirements:
fmust be a function that accepts an n-dimensional vectorxand returns an integrand. The integrand can be a real number, complex number, vector, or matrix (any type supporting+,-,*real, andnorm).aandbmust be vectors or tuples of lengthnrepresenting the integration limits for each dimension.- For performance with vector/matrix-valued integrands, it is recommended to use
StaticArrays.jl. - The integrand
f(x)will be passed anSVector{n,T}from theStaticArrayspackage.
Return Value:
A tuple (I, E) where I is the estimated integral and E is the estimated error.
using HCubature
# Example: 2D integral
f(x) = x[1] * x[2]
a = [0, 0]
b = [1, 1]
I, E = hcubature(f, a, b)