Cubature.jl icon indicating copy to clipboard operation
Cubature.jl copied to clipboard

hquadrature hangs for function that integrates to zero (unless abstol is set)

Open ngiann opened this issue 6 years ago • 2 comments

hquadrature(sin, 0.0, 2*pi)

Info on my machine and Julia version:

Julia Version 0.6.1 Commit 0d7248e2ff (2017-10-24 22:15 UTC) Platform Info: OS: Linux (x86_64-pc-linux-gnu) CPU: Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell) LAPACK: libopenblas64_ LIBM: libopenlibm LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

ngiann avatar Dec 08 '17 10:12 ngiann

For future reference, it helps to specify an absolute tolerance to ensure convergence: hquadrature(sin, 0.0, 2*pi,abstol = 1e-8) (Found on https://stackoverflow.com/questions/29292614/how-to-do-two-variable-numeric-integration-in-julia#comment46814673_29302840)

SalmonLA avatar Nov 11 '21 09:11 SalmonLA

As explained in the manual:

More precisely, the integration will terminate when either the relative- or the absolute-error tolerances are met. abstol defaults to 0, which means that it is ignored, but it can be useful to specify an absoute error tolerance for integrands that may integrate to zero (or nearly zero) because of large cancellations, in which case the problem is ill-conditioned and a small relative error tolerance may be unachievable.

The question is whether there is a way for us to reliably detect that you have specified an unachievable relative tolerance here, in order to terminate automatically.

(One idea that has been suggested is to estimate the integral of |f(x)| or similar, in order to be able to set a default absolute tolerance relative to this.)

stevengj avatar Nov 15 '23 12:11 stevengj