3
$\begingroup$

I want a numerical method to evaluate:

$$\log \int_a ^b f(x) \mathrm{d}x$$

when what I have is a numerical routine to evaluate $\log f(x)$. The problem is that if $f(x)$ takes very large or very small values, direct evaluation of $f(x)$ will lead to overflows/underflows. I am wondering if anyone has approached this numerical integration problem in general?

Note that even though $f(x)$ can be very small in some regions and very large in other regions, you can't just approximate the small values to zero, because if the region where $f(x)$ is very small is large enough, it may contribute significantly to the integral.

$\endgroup$
1
  • $\begingroup$ If $f$ does not vary too much, you can try to normalize it by just one (or a couple) of its values: pick a point $x_1$ and compute $\log f(x_1) + \log\int e^{\log f(x)-\log f(x_1)}\,dx$. That might be enough avoid over-/underflows in the exponentials, depending on how the function behaves. $\endgroup$ – Kirill Apr 28 '15 at 21:34
1
$\begingroup$

You say that $f(x)$ has both very large and very small (positive) values. Then the integral you have is "large", and the small values of $f(x)$ don't matter very much: in those areas where $f(x)$ would produce an underflow, you might as well add zeros because the contributions of this to the overall integral do not matter.

So what matters are those areas where $f(x)$ is so large that you get overflows. This must happen because you have some kind of singularity at these locations. If so, it would be worth splitting $f(x)$ into its singular and non-singular parts and integrating the singular parts analytically if possible, and the remainder term with quadrature.

$\endgroup$
8
  • $\begingroup$ I did not say that $f(x)$ takes both very large and very small values. I said it takes very small values or very large values. These are two separate situations. $\endgroup$ – becko Apr 28 '15 at 17:05
  • $\begingroup$ Ah, I read the statement that for different values of $x$, $f(x)$ may be large or small. Are you saying that it is always large, or always small? $\endgroup$ – Wolfgang Bangerth Apr 28 '15 at 17:29
  • $\begingroup$ Yes, that's what I am saying. $\endgroup$ – becko Apr 28 '15 at 18:07
  • $\begingroup$ In that case, can't you just normalize $f(x)$ by dividing it by a "typical size"? $\endgroup$ – Wolfgang Bangerth Apr 29 '15 at 3:02
  • 4
    $\begingroup$ Yes. We can go on forever with this, though. It would be more productive if you state what you know about $f(x)$ in the question. $\endgroup$ – Wolfgang Bangerth Apr 29 '15 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.