JuliaMath / Cubature.jl

One- and multi-dimensional adaptive integration routines for the Julia language
Other
126 stars 21 forks source link

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

Open ngiann opened 6 years ago

ngiann commented 6 years ago

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 NOAFFINITY Haswell) LAPACK: libopenblas64 LIBM: libopenlibm LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

SalmonLA commented 2 years ago

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)

stevengj commented 9 months ago

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.)