2

What methods are available to integrate a sharply peaked function (position of peak known) on a finite interval (the interval includes the peak)?

Currently I am getting underflows using some of GSL's adaptive algorithms. I suspect that GSL fails to find the position of the peak, and hence is thinks that the function is mostly zero. Is there a method in GSL so that I can tell where the peak is located? Or maybe I can use an alternative routine (it doesn't have to be GSL)?

a06e
  • 1,729
  • 15
  • 22
  • 1
    What is the function? Can you plot its graph or do you know its closed form? – Bill Barth Apr 20 '15 at 13:18
  • I hope a general solution is possible in which the specific form of the function can be obviated. However, if you need the details, this is the sort of function I am trying to integrate: http://stats.stackexchange.com/q/147321/5536 – a06e Apr 20 '15 at 14:45
  • @becko Can you tell us what "large $\alpha_i$, $\beta_i$" means? From your question at stats, the function is a polynomial, no? If you know the peak (and you know there is only one), why not use the adaptive GSL routine with integration end-points close to the peak? You could add some iteration by gradually increasing the integration interval and stop at convergence.... – GertVdE Apr 20 '15 at 17:27
  • @GertVdE It is not a polynomial, since $\alpha,\beta$ are not integers in general. I tried splitting the integration interval in two at the position of the peak, but it didn't help. Perhaps I am using the wrong GSL function (currently I am using https://www.gnu.org/software/gsl/manual/html_node/QAGS-adaptive-integration-with-singularities.html#QAGS-adaptive-integration-with-singularities). – a06e Apr 21 '15 at 12:38

1 Answers1

8

If you know where the peak is, then you can always split the interval. For example, if you know that the peak is at $a$ and has a "width" (however you want to define that) of $\sigma$ so that you can say that it is mostly confined within $[a-\sigma,a+\sigma]$, then split the integral as $$ \int_l^u f(x) \; dx = \int_l^{a-\sigma} f(x) \; dx + \int_{a-\sigma}^{a+\sigma} f(x) \; dx + \int_{a+\sigma}^u f(x) \; dx. $$ Each of these three integrals should now be relatively well-behaved on their own, and should be easy enough to integrate.

Wolfgang Bangerth
  • 55,373
  • 59
  • 119
  • should "not" or should "now" be well-behaved? – André Apr 21 '15 at 09:29
  • This is the function I need to integrate: http://stats.stackexchange.com/q/147321/5536. Finding the position of the peak is straightforward because the derivative is a decreasing function and a bissection finds its zero easily. But how do I estimate the $\sigma$? – a06e Apr 21 '15 at 12:40
  • @becko: Plot it? Or just sample at a few points $a+10, a+5, a+2.5, a+1.25, \ldots$, until the value starts to deviate significantly from the background value. – Wolfgang Bangerth Apr 21 '15 at 12:44