NIntegrate Error in Mathematica

In summary, NIntegrate is a function that determines how many points to use in the numerical integration. It looks at the function itself and determines 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.
  • #1
EngWiPy
1,368
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
  • #2
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
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
 
  • #4
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
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
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
 
  • #7
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
 
  • #8
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.
 
  • #9
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 [tex]10^{-13}[/tex] and lower, which is ignored, since the common range of performance curves such as SER is [tex][10^{-6},1][/tex]. 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
 

1. What is NIntegrate Error in Mathematica?

NIntegrate Error in Mathematica is an error message that appears when there is an issue with the numerical integration function in the Mathematica software. It can occur when there are problems with the input parameters or when the integration process encounters difficulties.

2. How do I fix NIntegrate Error in Mathematica?

The first step in fixing NIntegrate Error in Mathematica is to carefully check the input parameters and make sure they are correct. You can also try increasing the precision or using different integration methods. If the error persists, it may indicate a more complex issue that requires further troubleshooting or assistance from Mathematica support.

3. Can NIntegrate Error in Mathematica be avoided?

While it is not always possible to completely avoid NIntegrate Error, there are steps you can take to minimize its occurrence. This includes checking the input parameters, using appropriate integration methods, and increasing the precision when necessary. It may also be helpful to break down complex integrals into smaller, more manageable parts.

4. What are some common causes of NIntegrate Error in Mathematica?

NIntegrate Error can be caused by a variety of factors such as incorrect input parameters, singularities or discontinuities in the integrand, or convergence issues. It can also occur when the integration process exceeds the system limits or when there are errors in the underlying mathematical functions being integrated.

5. Is there a way to troubleshoot NIntegrate Error in Mathematica?

Yes, Mathematica has built-in tools and resources to help troubleshoot NIntegrate Error. This includes the "NIntegrate::" error codes that provide more specific information about the error, as well as the "EvaluationMonitor" option which allows you to track the progress of the integration process. Additionally, you can consult the Mathematica documentation or seek assistance from the Mathematica support team for more complex issues.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
34
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
Back
Top