NIntegrate Error in Mathematica

1. Jul 3, 2009

S_David

Hello all,

I have the following error while the command NIntegrate is executed in Mathematica:

Code (Text):
NIntegrate::slwcon: Numerical integration converging too slowly; \
suspect one of the following: singularity, value of the integration \
is 0, highly oscillatory integrand, or WorkingPrecision too small. >>

NIntegrate::ncvb: NIntegrate failed to converge to prescribed \
accuracy after 9 recursive bisections in y near {y} = {1.5301}. \
NIntegrate obtained 2.817606086983439*^-17 and \
5.338249419658235*^-23 for the integral and error estimates. >>
What is that mean? and should I care about it?

Regards

2. Jul 3, 2009

Staff: Mentor

NIntegrate is a pretty nice function that does a lot of things for you automatically internally. One of those things is to determine how many points to use in the numerical integration. If you have a nice smooth function then you can use only a few points, but if your function is very wiggly then you need to use a lot of points in order to get a good answer. NIntegrate looks at the function itself and determines how many points to use.

One method that it uses to do so is the accuracy. It estimates the error and uses that to determine how accurate the numerical integration is. If your function wiggles around a lot (e.g. Sin[1/x] around x=0) then the error will be high. If your function has a lot of terms and your numerical precision is low then the error will be high. If your function integrates to exactly 0 then any error, no matter how small, will be high relative to the value of the function.

It looks like your integral may be exactly 0.

3. Jul 3, 2009

S_David

Indeed it is a nice function, because I tried to use the numerical integration in MATLAB, which is very difficult to use, and generates a dozen of errors. In fact, Mathematica at all is a very nice software tool that does a lot of things very easily.

Anyway, concerning the error, I have values after it, shall I take them, or ignore them? I don't know how to handle them. The integrand in some cases becomes 0, so, the integral will evaluate to zero, as you said. If this is the case, shall I consider the results?

Best regards

4. Jul 3, 2009

Cvan

What's the function, just out of curiosity? If MATLAB is giving you nonsense, you could always do it the old fashioned way and write a quick function to use the numerical integration method and step size you want. You know, literally just summing the areas with a loop.

5. Jul 3, 2009

Staff: Mentor

Plot your function, if it is really wiggly then you know it is oscillatory and you probably won't get good results. On the other hand, if it has a lot of terms then you may just need to increase the working precision. Or look at the plot and if it looks like the area above the axis may be the same as the area under the axis then just don't worry about it.

6. Jul 3, 2009

S_David

Actually, I am plotting the Symbol Error Probability (SEP) of a wireless communication system, which is by definition from 0 to 1. So, I don't have area under the axis and above the axis, unless I misunderstood you. Anyway, the resultant curve decays smoothly to zero as expected. Is this a good sign?

Regards

7. Jul 3, 2009

S_David

I am not sure if I understand you, but after several weeks stucked on MATLAB trying to solve a complex function, that I can not write here for many reasons, in a very short time, I had all what I needed using Mathematica easily.

Regards

8. Jul 3, 2009

Staff: Mentor

In that case it sounds like something is wrong. Your function is strictly positive so it should have a positive integral, but yours is ~0. Plot the integrand and "eyeball" the area as a "reality check" on the result of the integration.

9. Jul 3, 2009

S_David

How can I do that? I am not so familiar with Mathematica, specially with the plot thing.

Regards

10. Jul 4, 2009

Staff: Mentor

If your function is f[x] then to plot f[x] from x=0 to x=10 use:

Plot[f[x],{x,0,10}]

11. Jul 4, 2009

Hurkyl

Staff Emeritus
It means your function is hard to numerically integrate. The error message offers several reasons why a function might be hard to numerically integrate.

Generally speaking, the practical effect is that you should not have much confidence in the answer you get. Some of your options are:
* Cross your fingers and hope the results are good enough
* Do a careful analysis of the error involved in the approximation to check if the answer is good. (This probably requires using your own integration function)
* Try and split the problem into the sum two parts: one that is exactly solvable, and one that is numerically integrable. (obviously, the first part is going to have to account for the bad numerical behavior of your function)

12. Jul 4, 2009

S_David

The aforementioned error appears at SER of $$10^{-13}$$ and lower, which is ignored, since the common range of performance curves such as SER is $$[10^{-6},1]$$. I faced with this problem in MATLAB previousely, at which, my professor said at the time, it is a precision issue, and I think it is the same case here.

May I didn't say that before, but the error dosen't appear in all cases, just in 2 or 3 cases among 12 or more cases.

Thank you very much Hurkyl for your reply, and the same of course for DaleSpam.

Best regards

13. Jul 4, 2009

Staff: Mentor

Then try something like NIntegrate[ ... , WorkingPrecision->50]. It will slow down the computation, but may allow it to converge correctly.

14. Jul 4, 2009

S_David

When I did that, the following error appeared from the very begining of the execution:

Code (Text):
NIntegrate::precw: The precision of the argument function ... is less than WorkingPrecision (50.`). >>
It is ok DaleSpam, I will just ignore these results, becuase I don't need them actually in plotting the performance curves as I mentioned. But I just wanted to make sure it is not a programming issue (i.e.: I programmed the code incorrectly), which seems not, since I get error-free results in other cases, and the trend of the curves is as expected; decay smoothly to zero.

Thank you very much.

Best regards