# Why does "QuadGK.jl" not behave the same as "Integrals.jl with QuadGKJL()"

**URL:** <https://discourse.julialang.org/t/why-does-quadgk-jl-not-behave-the-same-as-integrals-jl-with-quadgkjl/110795>\
**Category:** General Usage\
**Tags:** quadgk, integral\
**Created:** [February 26, 2024, 5:07pm UTC](https://discourse.julialang.org/t/why-does-quadgk-jl-not-behave-the-same-as-integrals-jl-with-quadgkjl/110795 "2024-02-26T17:07:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laura/32/207742_2.png) [@Laura](https://discourse.julialang.org/u/Laura)\
**Post date:** [February 26, 2024, 5:07pm UTC](https://discourse.julialang.org/t/why-does-quadgk-jl-not-behave-the-same-as-integrals-jl-with-quadgkjl/110795/1 "2024-02-26T17:07:37Z")

</div>

I am writing a program to perform a spherical Bessel transformation which requires some one dimensional integrals but I am having some trouble with the Integrals.jl package.

Naturally my first attempt to do this was to use QuadGK.jl but I also wanted to try using the Integrals.jl package since I might want to make use of it’s in place or batching features in the future. I am aware that the QuadGK.jl package also has in place features with quadgk! but even then I’d prefer to understand what I am doing wrong.

```julia
using QuadGK
using Integrals
using SpecialFunctions
using Plots

```

When I do this with the QuadGK package my code looks as follows:

```julia
function spherical_bessel_transform(f::Function, root::Float64, nu::Int64)::Float64

    norm = 2 / sphericalbesselj(nu + 1, root)^2;

    func = (x) -> x^2 * f(x) * sphericalbesselj(nu, root * x);

    return norm * quadgk(func, 0, 1; atol=1e-14, rtol=1e-14)[1];

end

```

When I do this with the Integrals package my code looks as follows:

```julia
function spherical_bessel_transform(f::Function, root::Float64, nu::Int64)::Float64

    norm = 2 / sphericalbesselj(nu + 1, root)^2;

    func = (x, p) -> x^2 * f(x) * sphericalbesselj(nu, root * x);

    prob = IntegralProblem(func, 0, 1; abstol = 1e-14, reltol = 1e-14);

    sol = solve(prob, QuadGKJL());

    return norm * sol.u;

end

```

I plot both of these methods for a test function as follows:

```julia
test_func = (x) -> exp(-x^2 * 10000);

test_roots = collect(1.0:500.0) * pi

plot(spherical_bessel_transform.(test_func, test_roots, 0))

```

They should both give the same results but the result using “Integrals.jl” does not look right.

 ![Untitled](https://global.discourse-cdn.com/julialang/original/3X/8/7/87a5ebf6a5592a9372347adb3a89317049c4654d.png)

I do not understand why these would give different results since they are supposedly using the same machinery under the hood.

> **[Numerically Solving Integrals · Integrals.jl](https://docs.sciml.ai/Integrals/stable/tutorials/numerical_integrals/#One-dimensional-integrals)**
>
> Documentation for Integrals.jl.

---

<div class="post-metadata">

**Author:** ![lxvm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lxvm/32/50010_2.png) [@lxvm](https://discourse.julialang.org/u/lxvm)\
**Post date:** [February 29, 2024, 3:28am UTC](https://discourse.julialang.org/t/why-does-quadgk-jl-not-behave-the-same-as-integrals-jl-with-quadgkjl/110795/2 "2024-02-29T03:28:10Z")

</div>

Hi, I took a look and I think that you are passing your tolerances to the `IntegralProblem` instead of to `solve`. The following should reproduce your QuadGK.jl result

```julia
function spherical_bessel_transform(f::Function, root::Float64, nu::Int64)::Float64

    norm = 2 / sphericalbesselj(nu + 1, root)^2;

    func = (x, p) -> x^2 * f(x) * sphericalbesselj(nu, root * x);

    prob = IntegralProblem(func, 0, 1);

    sol = solve(prob, QuadGKJL(); abstol = 1e-14, reltol = 1e-14);

    return norm * sol.u;

end

```

In this regard, the `IntegralProblem` documentation is misleading and could be improved since in fact “kwargs: Keyword arguments copied to the solvers” is not actually implemented.

---

<div class="post-metadata">

**Author:** ![lxvm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lxvm/32/50010_2.png) [@lxvm](https://discourse.julialang.org/u/lxvm)\
**Post date:** [February 29, 2024, 3:42am UTC](https://discourse.julialang.org/t/why-does-quadgk-jl-not-behave-the-same-as-integrals-jl-with-quadgkjl/110795/3 "2024-02-29T03:42:45Z")

</div>

Ref: [`IntegralProblem` keywords not passed to solvers · Issue #242 · SciML/Integrals.jl · GitHub](https://github.com/SciML/Integrals.jl/issues/242)

Thank you @Laura for reporting this!

---

<div class="post-metadata">

**Author:** ![Laura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laura/32/207742_2.png) [@Laura](https://discourse.julialang.org/u/Laura)\
**Post date:** [February 29, 2024, 7:08am UTC](https://discourse.julialang.org/t/why-does-quadgk-jl-not-behave-the-same-as-integrals-jl-with-quadgkjl/110795/4 "2024-02-29T07:08:36Z")

</div>

Passing the tolerance to the solver instead of the problem worked. Thank you very much.
