Mathematica NIntegrate Error in Mathematica

  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Error Mathematica
Click For Summary
The discussion revolves around an error encountered with the NIntegrate function in Mathematica, indicating that numerical integration is converging too slowly, possibly due to singularities or oscillatory behavior in the integrand. Users suggest that if the function is highly oscillatory or integrates to zero, the results may not be reliable. It is recommended to plot the function to visually assess its behavior and consider increasing the WorkingPrecision to improve convergence. The original poster notes that the errors occur infrequently and that the overall trend of their performance curves is as expected, suggesting that the issue may not be critical. Ultimately, they decide to ignore the problematic results for their specific application.
EngWiPy
Messages
1,361
Reaction score
61
Hello all,

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

Code:
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
 
Physics news on Phys.org
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.
 
DaleSpam said:
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.

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?

Thank you for replying DaleSpam.

Best regards
 
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.
 
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.
 
DaleSpam said:
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.

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
 
Cvan said:
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.

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
 
S_David said:
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?
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.
 
DaleSpam said:
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.

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

Regards
 
  • #10
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
S_David said:
What is that mean? and should I care about it?
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
Hurkyl said:
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)

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
S_David said:
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.
Then try something like NIntegrate[ ... , WorkingPrecision->50]. It will slow down the computation, but may allow it to converge correctly.
 
  • #14
DaleSpam said:
Then try something like NIntegrate[ ... , WorkingPrecision->50]. It will slow down the computation, but may allow it to converge correctly.

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

Code:
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
 

Similar threads

  • · Replies 34 ·
2
Replies
34
Views
4K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
7K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 43 ·
2
Replies
43
Views
5K