A convenient interface to perform 1D, 2D and 3D numerical integrations. Uses QuadGK.jl, Cuba.jl, HCubature.jl and FastGaussQuadrature.jl as back-ends.
Author aurelio-amerio
Popularity
4 Stars
Updated Last
2 Years Ago
Started In
January 2020

MultiQuad.jl is a convenient interface to perform 1D, 2D and 3D numerical integrations. It uses QuadGK, Cuba and HCubature as back-ends.

# Usage

## quad

quad(arg::Function, x1, x2; method = :quadgk, kwargs...)

It is possible to use quad to perform 1D integrals of the following kind: The supported adaptive integration methods are:

• :quadgk
• :vegas
• :suave

There are several fixed order quadrature methods available based on FastGaussQuadrature

• :gausslegendre
• :gausshermite
• :gausslaguerre
• :gausschebyshev
• :gaussradau
• :gausslobatto

If a specific integration routine is not needed, it is suggested to use :quadgk (the default option). For highly oscillating integrals, it is advised to use :gausslegendrewith a high order (~10000).

Please note that :gausshermite and :gausslaguerre are used to specific kind of integrals with infinite bounds.

See QuadGK and Cuba.jl for all the available keyword arguments.

### Example 1

Compute: using MultiQuad

func(x) = x^2*exp(-x)

# for certain kinds of integrals with infinite bounds, it may be possible to use a specific integration routine
func(x) = x^2*exp(-x)
# gausslaguerre computes the integral of f(x)*exp(-x) from 0 to infinity
quad(x -> x^4, method=:gausslaguerre, order=10000) 

### Example 2

It is possible to compute integrals with unit of measurement using Unitful.

For example, let's compute: using MultiQuad
using Unitful

func(x) = x^2
quad(func, 1u"m", 5u"m")

## dblquad

dblquad(arg::Function, x1, x2, y1::Function, y2::Function; method = :cuhre, kwargs...)
dblquad(arg::Function, x1, x2, y1, y2; method = :cuhre, kwargs...)

It is possible to use dblquad to perform 2D integrals of the following kind: The supported integration method are:

• hcubature (default)
• :cuhre
• :vegas
• :suave
• :divonne

It is suggested to use :hcubature (the default option).

See Cuba.jl and HCubature for all the available keyword arguments.

### Example 1

Compute: using MultiQuad

func(y,x) = sin(x)*y^2
integral, error = dblquad(func, 1, 2, x->0, x->x^2, rtol=1e-9)

### Example 2

It is possible to compute integrals with unit of measurement using Unitful.

For example, let's compute: using MultiQuad
using Unitful

func(y,x) = sin(x)*y^2
integral, error = dblquad(func, 1u"m", 2u"m", x->0u"m^2", x->x^2, rtol=1e-9)

### Example 3

Compute: using MultiQuad

func(y,x) = sin(x)*y^2
integral, error = dblquad(func, 1, 2, 0, 4, rtol=1e-9)

## tplquad

tplquad(arg::Function, x1, x2, y1::Function, y2::Function, z1::Function, z2::Function; method = :cuhre, kwargs...)

It is possible to use quad to perform 3D integrals of the following kind: The supported integration method are:

• :cuhre (default)
• :vegas
• :suave
• :divonne

It is suggested to use :cuhre (the default option)

See Cuba.jl for all the available keyword arguments.

### Example 1

Compute: using MultiQuad

func(z,y,x) = sin(z)*y*x
integral, error = tplquad(func, 0, 4, x->x, x->x^2, (x,y)->2, (x,y)->3*x)

### Example 2

It is possible to compute integrals with unit of measurement using Unitful.

For example, let's compute: using MultiQuad
using Unitful

func(z,y,x) = sin(z)*y*x
integral, error = tplquad(func, 0u"m", 4u"m", x->0u"m^2", x->x^2, (x,y)->0, (x,y)->3)

### Example 3

Compute: using MultiQuad

func(z,y,x) = sin(z)*y*x
integral, error = tplquad(func, 0, 4, 1, 2, 2, 3)

### Used By Packages

No packages found.