Numerical integration using hcubature\

Hello everyone,

I’m transitioning from python to Julia and I’m trying to compute some integrals using hcubature

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

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:

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 the following way:

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!

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> hcubature(x -> log(cosh(2 * β) ^ 2 - sinh(2 * β) * (cos(x[1]) + cos(x[2]))), (0,0), (pi,pi))
(25.80311552225346, 3.6094762639882205e-7)

Thank you for pointing that out!! :slight_smile:

1 Like