# Nested QuadGK: Long compilation time gets short when plotting the argument beforehand, but not when calling it

**URL:** <https://discourse.julialang.org/t/nested-quadgk-long-compilation-time-gets-short-when-plotting-the-argument-beforehand-but-not-when-calling-it/24519>\
**Category:** General Usage\
**Tags:** compilation\
**Created:** [May 23, 2019, 2:08pm UTC](https://discourse.julialang.org/t/nested-quadgk-long-compilation-time-gets-short-when-plotting-the-argument-beforehand-but-not-when-calling-it/24519 "2019-05-23T14:08:42Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [May 24, 2019, 3:34pm UTC](https://discourse.julialang.org/t/nested-quadgk-long-compilation-time-gets-short-when-plotting-the-argument-beforehand-but-not-when-calling-it/24519/3 "2019-05-24T15:34:57Z")

</div>

I don’t have an explanation for the compilation time — you might file an issue at JuliaLang/julia — but I would strongly recommend against using nested 1d adaptive quadrature, which can easily waste a lot of time trying to refine 1d integrals in regions that don’t contribute much to the overall integral.

Instead, you should use a “cubature” routine (like in HCubature.jl, Cubature.jl, or Cuba.jl) that knows how to do multiple integrals in a holistic way. Even though these routines typically integrate over box domains, you can integrate over other domains with a change of variables. For example, your problem is a triangular domain, which can be mapped to a box with:

\int\_0^1 dx \int\_0^x dy \, F(x,y) = \int\_0^1 dx \int\_0^1 du \, xF(x,ux)

via the change of variables y = ux.

---

_[View the full topic](https://discourse.julialang.org/t/nested-quadgk-long-compilation-time-gets-short-when-plotting-the-argument-beforehand-but-not-when-calling-it/24519)._
