# Choosing order in QuadGK

**URL:** <https://discourse.julialang.org/t/choosing-order-in-quadgk/13534>\
**Category:** Numerics\
**Created:** [August 15, 2018, 11:31pm UTC](https://discourse.julialang.org/t/choosing-order-in-quadgk/13534 "2018-08-15T23:31:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sverek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sverek/32/30484_2.png) [@sverek](https://discourse.julialang.org/u/sverek)\
**Post date:** [August 15, 2018, 11:31pm UTC](https://discourse.julialang.org/t/choosing-order-in-quadgk/13534/1 "2018-08-15T23:31:56Z")

</div>

Anybody has a rough idea how I should set the order of QuadGK for a standard mass matrix element calculation (Lagrange element) with order `p^2` and `BigFloat` precision `N`

i read this in documentation:

`It is advisable to increase the integration order in rough proportion to the precision, for smooth integrands.`

and it is not very clear so me. Say I want `p=20` and `N=1000`, then what order for the quadrature should I set?

---

<div class="post-metadata">

**Author:** ![sverek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sverek/32/30484_2.png) [@sverek](https://discourse.julialang.org/u/sverek)\
**Post date:** [August 16, 2018, 5:16am UTC](https://discourse.julialang.org/t/choosing-order-in-quadgk/13534/2 "2018-08-16T05:16:28Z")

</div>

And yes, I need these kinds of matrices. It is not for FEM calculations. Doing it symbolically would be ok too if somebody has some hints.

---

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [August 16, 2018, 8:23am UTC](https://discourse.julialang.org/t/choosing-order-in-quadgk/13534/3 "2018-08-16T08:23:18Z")

</div>

Is your question for a given N, how to choose p? Otherwise I don’t understand the question. For a smooth integrand (technically, it depends on the region of analyticity), you can expect that the error of a Lagrange interpolation with p points behaves as exp(-c p) where c is a constant. Therefore, if you find out that a given p gives you N digits, you should use 2p to give you 2N digits.

---

<div class="post-metadata">

**Author:** ![sverek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sverek/32/30484_2.png) [@sverek](https://discourse.julialang.org/u/sverek)\
**Post date:** [August 16, 2018, 10:10am UTC](https://discourse.julialang.org/t/choosing-order-in-quadgk/13534/4 "2018-08-16T10:10:01Z")

</div>

Bad choice of notation from my part `N` here is the precision of BigFloat in bits, I need to do many different runs with varying number of bits, some over 3000 bits. I need to do for varying order of the Lagrange polynomials (up to maybe p=50, doing up to 20 now). Code works fine but already at p=7 it is very slow. We are talking about 12 hours for a tiny matrix (mixing up questions now, ignore the size of the matrix, here I am talking about the specific elements for assembly, in other parts of the code I am computing the eigenvalues which is of course not related) maybe 256 bit precision and p=10. In documentation of QuadGK [Home · QuadGK.jl](https://juliamath.github.io/QuadGK.jl/stable/)  
It states that one should increase the integration order of QuadGK with precision. I am not setting it to anything at the moment and letting it choose by itself.

So my question is: For a given `p` and `N`, what would be an appropriate argument `order=x` to the function `quadgk` to make it faster, I assume it is slow because it is adaptively increasing this order. I could always try but since one run is about 12h it is a bit awkward 🙂
