# Numerical integration using hcubature\\

**URL:** <https://discourse.julialang.org/t/numerical-integration-using-hcubature/62221>\
**Category:** Numerics\
**Tags:** question\
**Created:** [June 1, 2021, 7:42pm UTC](https://discourse.julialang.org/t/numerical-integration-using-hcubature/62221 "2021-06-01T19:42:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danrib07](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danrib07/32/212751_2.png) [@danrib07](https://discourse.julialang.org/u/danrib07)\
**Post date:** [June 1, 2021, 7:42pm UTC](https://discourse.julialang.org/t/numerical-integration-using-hcubature/62221/1 "2021-06-01T19:42:14Z")

</div>

Hello everyone,

I’m transitioning from python to Julia and I’m trying to compute some integrals using [hcubature](https://github.com/JuliaMath/HCubature.jl)

I’m trying to compute the following integral, for which the constant \beta is equal to 1

 ![Screen Shot 2021-06-01 at 2.38.11 PM](https://global.discourse-cdn.com/julialang/original/3X/9/b/9b401a2428e95f55b31576bd7f80718b799baf37.png)

As seen from the picture, the numerical result to the integral is approximately 25.80

In Julia, I am trying to compute the integral above this way:

```julia
using HCubature
β = 1
hcubature(x -> log(cosh(2 * β) ^ 2 - sinh(2 * β) * (cos(x[1]) + cos(x[2]))), (pi, 0), (pi,0))[1]

```

which gives 0.0 as the answer.

In python, I would compute the same integral using [nquad](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.nquad.html) the following way:

```julia
import numpy as np
from scipy.integrate import nquad
ff = lambda x1, x2: np.log(np.cosh(2 * beta) ** 2 - np.sinh(2 * beta) * (np.cos(x1) + np.cos(x2)))
nquad(ff, [[0, np.pi], [0, np.pi]])[0]

```

this gives me the correct result of 25.80.

What am I doing wrong with hcubature?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [June 1, 2021, 7:55pm UTC](https://discourse.julialang.org/t/numerical-integration-using-hcubature/62221/2 "2021-06-01T19:55:53Z")

</div>

I think you’ve just got the bound arguments mixed up, its not `(xmin, xmax), (ymin, ymax)` rather its `(xmin, ymin), (xmax, ymax)`, so should be

```julia
julia> hcubature(x -> log(cosh(2 * β) ^ 2 - sinh(2 * β) * (cos(x[1]) + cos(x[2]))), (0,0), (pi,pi))
(25.80311552225346, 3.6094762639882205e-7)

```

---

<div class="post-metadata">

**Author:** ![danrib07](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danrib07/32/212751_2.png) [@danrib07](https://discourse.julialang.org/u/danrib07)\
**Post date:** [June 1, 2021, 8:11pm UTC](https://discourse.julialang.org/t/numerical-integration-using-hcubature/62221/3 "2021-06-01T20:11:10Z")

</div>

> [@marius311](#):
>
> `julia> hcubature(x -> log(cosh(2 * β) ^ 2 - sinh(2 * β) * (cos(x[1]) + cos(x[2]))), (0,0), (pi,pi))`

Thank you for pointing that out!! 🙂
