2D integration over non-rectangular domain using cubature

Hello everyone,

I have a very basic question.
I’m looking for the most efficient way to perform the following very classical integral:

For now I’m using hquadrature of the cubature package in two steps.

This works, but I’m not sure whether this is the most efficient way.
More generally, I would like to know, how to perform multidimensional integration over non-rectangular domains.
It seems cubature does not allow bounds to be functions. Am I correct?

Many thanks in advance
Olivier

2 Likes

You can use a change of variables in general. However, since your problem is separable in x and u, you should take advantage of that, eg approximate the integral of g(u)du from 0 to x as some G(x), similarly for f, and then F(a)G(x) is your answer.

(BTW, does the forum allow LaTeX now? or was that inserted as an image?)

1 Like

Thanks for your answer,
Ok, I will stick with two-step approach then.

BTW, yes, it’s an image. :slight_smile:

Why is the problem separable? The integration is over the x variable which is the limit of integration of the second integral.

In any case, your suggestion has been accepted.

The way I read this notation is that the dx closes the scope for the x, so the second x is a free variable. I am aware that some people follow a different convention, but I find that confusing.

It’s quite natural, once you get used to it, to think of as “\int dx” as the operator “integrate the following function with respect to x”

I would recommend trying a change of variables to turn the integration region into a rectangle. For example, let y=u/x, so that the integral becomes

In general, a 2d cubature code can be more efficient than nested 1d quadratures, assuming you are using adaptive quadrature/cubature. This is because the inner 1d integral, if it is performed as an independent 1d adaptive quadrature, can waste a lot of integrand evaluations trying to refine the 1d integral to high relative accuracy even if its overall contribution to the integral is small.

(There are also specialized cubature algorithms for triangular domains, but I’ve never seen an implementation of a nested/adaptive one.)

7 Likes

Thank you very much @stevengj for your answer.
That was exactly the information I was looking for.

I know in matlab you can actually use a function handle to define an integration region.
I was wondering if something similar was possible with one of the julia packages.

Thanks again

I’m not sure what you’re referring to — as far as I can tell, Matlab doesn’t include multi-dimensional integration routines.

This is what I found for Matlab R2017a

https://fr.mathworks.com/help/matlab/ref/integral2.html#btbbuxy-3

In older versions I used quad2d
In both versions you could pass a function handle (anonymous function) as an integration bound.

I quickly checked the publications cited at the end of the page, but I have no idea whether matlab actually implements the algorithms descibed in these or relies on something else.

There is no way to compute non rectangular Integral in julia???
this is the way that I do it in python:
func = lambda x,y: xy
integ = integrate.dblquad(x2,0,t,lambda x :x, lambda y: t)[0]
and this is the way that I do in matlab:
func = @(x,y) x
y;
integ = integral2(func,0,t,@(t1) t1,t);
but I dont know how I can compute it in julia.

As I explained when you asked about this in an HCubature.jl issue, just do a change of variables to transform to a rectangular region.

For example, to integrate f(x,y) for x=0…t and y=0…x (i.e. a triangle), just do the change of variables y=ux and integrate f(x,u*x)*x for x=0…t , u=0…1 (note the Jacobian factor *x multiplying f).

3 Likes