# Integral of a function inside non-rectangular domain

**URL:** <https://discourse.julialang.org/t/integral-of-a-function-inside-non-rectangular-domain/72132>\
**Category:** Numerics\
**Created:** [November 26, 2021, 9:10pm UTC](https://discourse.julialang.org/t/integral-of-a-function-inside-non-rectangular-domain/72132 "2021-11-26T21:10:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 26, 2021, 9:27pm UTC](https://discourse.julialang.org/t/integral-of-a-function-inside-non-rectangular-domain/72132/2 "2021-11-26T21:27:54Z")

</div>

> [@wsshin](#):
>
> I want to integrate some function f(x,y) inside a non-rectangular domain, say a disk defined by x² + y² ≤ 1.

Have you considered cylindrical coordinates?

In general, you want to do some change of variables to map the domain to a hypercube (or a collection thereof). See also [2D integration over non-rectangular domain using cubature - #7 by stevengj](https://discourse.julialang.org/t/2d-integration-over-non-rectangular-domain-using-cubature/2991/7)

> [@wsshin](#):
>
> I actually tried to define `g(x,y) = f(x,y) * (x^2+y^2 ≤1)`

The problem with integrating this is that now you have a discontinuous integrand. Quadrature schemes are generally designed for smooth integrands. (If you have a singularity, you want to build it into the quadrature scheme if possible.)

> [@wsshin](#):
>
> However, when I tried this with `HCubature` package, I was not able to get a solution for several minutes

Realize that `hcubature` defaults to \sqrt{\varepsilon} tolerance — so it is trying to integrate your discontinuous integrand to 8 significant digits by refining the domain, and it probably won’t converge until it has \> 10^8 subdomains; it’s not surprising that it takes a ridiculously long time.

---

_[View the full topic](https://discourse.julialang.org/t/integral-of-a-function-inside-non-rectangular-domain/72132)._
