When I try to integrate function $x(\log(x)-1)$ from $-1$ to $1$, analytically I get $0.0000 - 1.5708i$

When I try to integrate it numerically, using $10$ points gaussian quadrature I get $0.0000 - 1.5826i$. For $4$ gaussian points, the numerical integration gives me $0.0000 - 1.6376i$ as is expected for less number of gaussian points.

The thing that keeps puzzling me is when I split the integration into negative region and positive region and sum them up later, I will be able to get a perfect result. For example, for bounds $[-1,0]$ with $10$ gaussian points, the numerical integration gives $0.7500 - 1.5708i$. Similarly for bounds $[0,1]$, it gives $-0.75$. Adding the split parts up will give me the correct result of $0.0000 - 1.5708i$.

So again, why is splitting the numerical integration for function consisting of logarithm on negative and positive axis required for better accuracy?

  • 2
    $\begingroup$ How do you do the integration? If you pass through $\;z=0\;$ then there is a huge problem with $\;\log z\;$ . $\endgroup$ – DonAntonio Mar 14 '16 at 11:26
  • 1
    $\begingroup$ it's simply 0. I mean, x*log(x) will give 0. And for any number close to the x->0, be it 0.000001 or -0.000001 you will still get a number converging to zero. Therefore you don't have to worry about the singularity as there simply isn't any (from my knowledge) $\endgroup$ – cylee Mar 14 '16 at 11:42
  • 1
    $\begingroup$ @cylee: The (limiting) value $0 \log 0 - 1$ may be zero mathematically (for a fixed branch of $\log$ along the real axis), but it's probably NaN in all computer languages. It's impossible to be specific without knowing internal details of your software. :) $\endgroup$ – Andrew D. Hwang Mar 14 '16 at 11:56
  • 1
    $\begingroup$ since the only NaN (matlab) as you said is, at zero, the algorithm is rather simple by converting this only NaN to 0 value. In practice, however, the even number of gaussian points are never at zero so writing that algorithm is optional, i.e., number of gaussian points in the above example is 10. $\endgroup$ – cylee Mar 14 '16 at 14:58

Your Answer

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

Browse other questions tagged or ask your own question.