# QuadGK unexpected behavior on first degree polynomial

**URL:** <https://discourse.julialang.org/t/quadgk-unexpected-behavior-on-first-degree-polynomial/113134>\
**Category:** Numerics\
**Tags:** question, quadgk, integral\
**Created:** [April 18, 2024, 9:38am UTC](https://discourse.julialang.org/t/quadgk-unexpected-behavior-on-first-degree-polynomial/113134 "2024-04-18T09:38: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:** [April 18, 2024, 12:54pm UTC](https://discourse.julialang.org/t/quadgk-unexpected-behavior-on-first-degree-polynomial/113134/2 "2024-04-18T12:54:17Z")

</div>

> [@Domenico\_Lahaye](#):
>
> hangs in performing computations.

You aren’t setting any tolerance in these integrals, so it is using the default _relative_ tolerance of \approx 10^{-8}. This is a problem here because the integral `fooint` is actually zero, so a _relative_ tolerance `|err| ≤ rtol * |int|` can never be satisfied (unless the error is exactly zero), so it will keep refining the integrals until it hits the limits of machine precision (which will take a long time in 2d).

Passing an absolute tolerance `atol=1e-8` to both `quadgk` calls causes the calculation to run very quickly.

(You might also look into IteratedIntegration.jl for performing nested `quadgk` calls more efficiently. Or HCubature.jl via a [change of variables](https://discourse.julialang.org/t/how-to-compute-the-integration-of-the-following-formula-by-hcubature/32269/2) to map to a rectangular domain. Or, if you are really just integrating low-degree polynomials and similar very smooth functions, use a tensor-product of fixed-order Gaussian quadrature rules, or SimplexQuad.jl, or similar.)

---

_[View the full topic](https://discourse.julialang.org/t/quadgk-unexpected-behavior-on-first-degree-polynomial/113134)._
