giordano / Cuba.jl

Library for multidimensional numerical integration with four independent algorithms: Vegas, Suave, Divonne, and Cuhre.
https://giordano.github.io/Cuba.jl/stable
MIT License
75 stars 9 forks source link

Integration on general domains #20

Closed arbenede closed 5 years ago

arbenede commented 5 years ago

I am wondering if it possible to integrate an n-dimensional function on a set that is not an n-dimensional box in a way similar to the Monte Carlo integration routines in Numerical Recipes. If the function returns 0 when x is not in the set maybe this will just work in the current implementation of Cuba.jl?

giordano commented 5 years ago

I'm not sure I understand what you mean, could you please provide an example of what you would like to do? If you're asking for a way to integrate a domain different from the n-dimensional hypercube, then read the first "tip" box in the documentation: https://giordano.github.io/Cuba.jl/stable/

arbenede commented 5 years ago

Say that I want to integrate on a domain A that is not a hyper-rectangle (in my case A is a n-dimensional convex polytope but that does not really matter here). What I would do is to compute the smallest hyper-rectangle B such that A \in B and pass the bounds defined by B to Cuba. The function to be integrated would just return f(x) = 0 if x \in (B \ A). Do you think this would work?

giordano commented 5 years ago

If you are going to integrate a function on a domain larger than what you want, and define the integrand such that it returns zero outside the domain on which you actually want to integrate, yes, that would do the trick.

giordano commented 5 years ago

@arbenede did it solve your issue?

arbenede commented 5 years ago

Mose`, I did not have a chance to try this yet however I think that you can close this issue for now.

giordano commented 5 years ago

I'm going to close this issue, then. Feel free to ping me here if you come across the same problem again