What does a maximum number of intervals warning mean in numerical integration?

In summary: With ##jt## as the lower limit you have ##\int f'(t)f^2(t)~dt##.MATLAB gives me wrong results. I am expecting a real number result between 0 and 1, but it gives me a large number in the order of ##10^3## and more! How can I address the warning properly?
  • #1
EngWiPy
1,368
61
Hi,

I am trying to evaluate the following integral numerically in MATLAB

[tex]\int_0^{\infty}\frac{e^{-jt}E_1^2(-jt)}{t}\,dt[/tex]

where ##j=\sqrt{-1}##, and ##E_1(x)## is the exponential integral.

My code is

Code:
fun = @(x) (exp(-1i*x).*(expint(-1i*x)).^2)./x;
q = integral(fun,0,Inf)

but I get the following warning message

Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 3.2e+04. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.

What does this mean? Does it mean that the integral doesn't exist? Or I need to increase the precision?

Thanks
 
Physics news on Phys.org
  • #3
Thanks, but I need a more specific answer to what is wrong in my case. The link you provided indicates there is a problem at certain values for their expression, which are different than mine.
 
  • #4
EngWiPy said:
Hi,

I am trying to evaluate the following integral numerically in MATLAB

[tex]\int_0^{\infty}\frac{e^{-jt}E_1^2(-jt)}{t}\,dt[/tex]

where ##j=\sqrt{-1}##, and ##E_1(x)## is the exponential integral.
There is no standard definition of ##E_1(x)##. Is it your intent to find a value for ##\int_0^{\infty}\frac{e^{-jt}}{t}\left(\int_{-jt}^{\infty} \frac {e^{-x}}x~dx\right)^2\,dt## ?
Note in particular the lower integration limit, i.e. ##-jt##.
 
  • #5
tnich said:
There is no standard definition of ##E_1(x)##. Is it your intent to find a value for ##\int_0^{\infty}\frac{e^{-jt}}{t}\left(\int_{-jt}^{\infty} \frac {e^{-x}}x~dx\right)^2\,dt## ?
Note in particular the lower integration limit, i.e. ##-jt##.

Yes, I use this definition of the exponential integral. So, I cannot evaluate the exponential integral because of the lower limit?
 
  • #6
EngWiPy said:
Yes, I use this definition of the exponential integral. So, I cannot evaluate the exponential integral because of the lower limit?
I asked that question because a lower limit of ##jt## for the inner integral (without the minus sign) would allow you to find an analytic solution. However, I think it is the lower limit (zero) of the outer integral that is causing your problem. Try a small positive value for that limit and see if MATLAB finds a solution. I think you will find that as that lower limit decreases toward zero, the value of the integral gets very large very quickly.
 
  • #7
tnich said:
I asked that question because a lower limit of ##jt## for the inner integral (without the minus sign) would allow you to find an analytic solution. However, I think it is the lower limit (zero) of the outer integral that is causing your problem. Try a small positive value for that limit and see if MATLAB finds a solution. I think you will find that as that lower limit decreases toward zero, the value of the integral gets very large very quickly.

When I put 0.001 as a lower limit instead of zero, I didn't get the warning. But I got it again when I changed the power of the exponential integral.

I have been trying to find an analytical solution, but with no success so far. I found some formulas for ##E_1^m(x)## in terms of simpler functions like this one

[tex]E_s^m(x)=\frac{1}{\Gamma(m+1)}\int_1^{\infty}\log(t)^m\,t^{-s}\exp(-tx)\,dt[/tex]

but stuck at evaluating an integral in the form of ##\int_0^{\infty}\frac{e^{-jt\alpha}}{t}\,dt## numerically.

Why the negative sign won't allow me to find an analytical solution? and what is the solution with a positive sign?

Thanks
 
Last edited:
  • #8
EngWiPy said:
When I put 0.001 as a lower limit instead of zero, I didn't get the warning. But I got it again when I changed the power of the exponential integral.

I have been trying to find an analytical solution, but with no success so far. I found some formulas for ##E_1^m(x)## in terms of simpler functions like this one

[tex]E_s^m(x)=\frac{1}{\Gamma(m+1)}\int_1^{\infty}\log(t)^m\,t^{-s}\exp(-tx)\,dt[/tex]

but stuck at evaluating an integral in the form of ##\int_0^{\infty}\frac{e^{-jt\alpha}}{t}\,dt## numerically.

Why the negative sign won't allow me to find an analytical solution? and what is the solution with a positive sign?

Thanks
With ##jt## as the lower limit you have ##\int f'(t)f^2(t)~dt##.
 
  • #9
MATLAB gives me wrong results. I am expecting a real number result between 0 and 1, but it gives me a large number in the order of ##10^3## and more! How can I address the warning properly? I think this warning says something about the wrong result.
 
  • #10
EngWiPy said:
MATLAB gives me wrong results. I am expecting a real number result between 0 and 1, but it gives me a large number in the order of ##10^3## and more! How can I address the warning properly? I think this warning says something about the wrong result.
Series representations of ##E_1(z)## include a ##-ln(z)## term. The value of ##-ln(0)## is ##\infty##. Why do you expect your integral to be finite?
If you work out the integral ##\int f'(t)f^2(t)~dt## with ##f(t) = E_1(jt)##, and then set ##t=0##, what do you get?
 
Last edited by a moderator:
  • #11
tnich said:
Series representations of ##E_1(z)## include a ##-ln(z)## term. The value of ##-ln(0)## is ##\infty##. Why do you expect your integral to be finite?
If you work out the integral ##\int f'(t)f^2(t)~dt## with ##f(t) = E_1(jt)##, and then set ##t=0##, what do you get?

Let me answer your question with a question: I am trying to find the cumulative distribution function (CDF) of a random variable from the characteristic function (CF). Now suppose that all the steps in evaluating the characteristic function, and the formula to find the CDF from the CF were correct, is it possible then to get an indefinite result? That is why I expect to get a finite result between 0 and 1 after some scaling, and the results here don't make sense in light of that, and I am suspecting to have some implementation issues (unless something wrong in the mathematical derivations).
 
Last edited:
  • #12
[I'll just throw this out as an idea. There are a few sites online that perform integrations. Although in the past I was surprised by their capabilities, I'm not sure whether they are sophisticated enough to handle what you're doing. But that approach could take you outside of the Matlab realm--to potentially provide data points for comparison purposes.]
 
  • #13
I am tying to have Mathematica installed. I have never used MATLAB for numerical integration before, but I used Mathematica, and I think it is better in handling numerical integration than MATLAB. Anyway, could you provide me with links to some of these websites to try them?
 
  • #15
When I tried to evaluate the integral using the first link, it said that the standard computation time exceeded, and the result was that the integral does not converge.
 
  • #16
EngWiPy said:
When I tried to evaluate the integral using the first link, it said that the standard computation time exceeded, and the result was that the integral does not converge.

I think subconsciously I remembered occasionally seeing that when I saw the MATLAB limit-error you noted. Not that they are related.

Maybe take a little time and play with the sites. I recall that at least one of them has options for something like: "use numerical only", etc. I guess I'm hoping there may be a way to break the problem down to help isolate things. Maybe one of the resident Math whizzes who are familiar with sites like these can chime in.
 
  • #17
EngWiPy said:
Let me answer your question with a question: I am trying to find the cumulative distribution function (CDF) of a random variable from the characteristic function (CF). Now suppose that all the steps in evaluating the characteristic function, and the formula to find the CDF from the CF were correct, is it possible then to get an indefinite result?
The short answer is no.
 
  • #18
tnich said:
The short answer is no.
The longer answer is, it looks like you are trying to convolve ##\frac 1 t## with itself. If that is the case, it is difficult to see how it could be either a CDF or a PDF unless it is constrained to a positive domain. In that case, the convolution would be similarly constrained. If that is not what you are trying to do, then maybe you have a mistake somewhere in your formulation or Fourier transforms.
 
  • #19
tnich said:
The longer answer is, it looks like you are trying to convolve ##\frac 1 t## with itself. If that is the case, it is difficult to see how it could be either a CDF or a PDF unless it is constrained to a positive domain. In that case, the convolution would be similarly constrained. If that is not what you are trying to do, then maybe you have a mistake somewhere in your formulation or Fourier transforms.
By the way, your Fourier transforms need an ##\omega## in them like this ##\int_{-\infty}^{\infty} e^{-j\omega t} f(t) ~dt##.
 
  • #20
Yes, there must be another variable I dropped for simplicity. Probably I need to check my derivations again. I am basically trying to find the CDF of the following random variable

[tex]\nu=\sum_{k=1}^K\frac{a_k}{b_k}[/tex]

where ##\{a_k, b_k\}## are i.i.d. exponential random variables with parameter 1.
 
  • #21
EngWiPy said:
Yes, there must be another variable I dropped for simplicity. Probably I need to check my derivations again. I am basically trying to find the CDF of the following random variable

[tex]\nu=\sum_{k=1}^K\frac{a_k}{b_k}[/tex]

where ##\{a_k, b_k\}## are i.i.d. exponential random variables with parameter 1.
OK. Rather than having me trying to reverse engineer your problem, why don't you just start at the beginning?
 
  • #22
I reached to this formula after asking many questions here over other forums about the mathematical details, and I was stuck on how to evaluate it. So, I was interested in the implementation details, rather than the mathematical derivations here. But if you can add anything to how I can evaluate the CDF mathematically (preferably without resorting to numerical integrations), that would great.
 
  • #23
EngWiPy said:
I reached to this formula after asking many questions here over other forums about the mathematical details, and I was stuck on how to evaluate it. So, I was interested in the implementation details, rather than the mathematical derivations here. But if you can add anything to how I can evaluate the CDF mathematically (preferably without resorting to numerical integrations), that would great.
How about a url for the thread with the derivation?
 
  • #24
tnich said:
How about a url for the thread with the derivation?

They were not about the derivations details, but rather the approach. Some members suggested to use the characteristic function because the means of the random variables ##a_k/b_k## are not defined (I originally wanted to use the moment generating function, but it doesn't work in this case). From there I continued from the definition of the characteristic function. But I can give you pieces of the derivations. First, is the characteristic function the way to go in your opinion?
 
  • #25
EngWiPy said:
They were not about the derivations details, but rather the approach. Some members suggested to use the characteristic function because the means of the random variables ##a_k/b_k## are not defined (I originally wanted to use the moment generating function, but it doesn't work in this case). From there I continued from the definition of the characteristic function. But I can give you pieces of the derivations. First, is the characteristic function the way to go in your opinion?
I used to ask for help the way you are doing it here. I would give a bare minimum of information and get back an answer that didn't help me.

I think I was parsimonious with information because I was afraid of exposing my ignorance, and I didn't want people to question the assumptions that had gotten me to the point where I was stuck. But in a lot of cases, those very assumptions were leading me astray.

I eventually learned to explain the overall problem I was trying to solve, why I wanted to solve it, and what I had figured out already. I found that people were much more willing to help me when I gave them the big picture, and that I got back useful information.
 
  • #26
Thanks for explaining. However, I think for me, it is more of wanting to simplify things to others. I think if I threw the whole problem out there at once, I would probably not get any answers. Besides, many details probably would be irrelevant to give an answer, such as the context and the application.

For this particular case, I presented the whole problem before but on other forums, and as I said here I am concerned with the implementation of the integration based on those discussions, and me pursuing the mathematical derivations using the suggested methods.

In general, I don't think people don't modify their problems to hide some details for whatever reason. I understand, it is difficult to receive the answers you want sometimes, but if necessary you can reveal more information.

Having said that, I will try to give some details in the coming days, and hopefully we can discuss them, and see together where I have (possibly) made a mistake.
 
  • #27
EngWiPy said:
Thanks for explaining. However, I think for me, it is more of wanting to simplify things to others. I think if I threw the whole problem out there at once, I would probably not get any answers. Besides, many details probably would be irrelevant to give an answer, such as the context and the application.

For this particular case, I presented the whole problem before but on other forums, and as I said here I am concerned with the implementation of the integration based on those discussions, and me pursuing the mathematical derivations using the suggested methods.

In general, I don't think people don't modify their problems to hide some details for whatever reason. I understand, it is difficult to receive the answers you want sometimes, but if necessary you can reveal more information.

Having said that, I will try to give some details in the coming days, and hopefully we can discuss them, and see together where I have (possibly) made a mistake.
Let me put it a little more strongly, then. When after two days and 19 posts, you finally reveal that you expect the result of the integration to be a CDF, and it clearly cannot be a CDF, I feel like you have wasted my time and effort.
 
  • Like
Likes jim mcnamara
  • #28
tnich said:
Let me put it a little more strongly, then. When after two days and 19 posts, you finally reveal that you expect the result of the integration to be a CDF, and it clearly cannot be a CDF, I feel like you have wasted my time and effort.

I am sorry you feel that your time and effort were wasted on this thread. I appreciate any help I can get here, and I try as much as I can to formulate my problems in a good way to help others understand it to give answers. My experience is that others tend to not respond when the problem is too complicated, and often they don't follow with their responses to help formulate a final answer. I am not here to waste others' time. It takes me time also to ask questions, explain and reply, and it isn't effective for me keep replying and posting. We could have discussed the mathematical details instead of this argument, and it would have taken probably the same time and effort, which would have been a more productive discussion. I don't expect to receive an answer from one response in the same day of posting. I don't mind getting an answer after days, as long as we are progressing in the answer and focusing on the problem.
 
Last edited:

FAQ: What does a maximum number of intervals warning mean in numerical integration?

What is numerical integration warning?

Numerical integration warning is a message that appears when there is a potential issue with the accuracy or convergence of a numerical integration method. It is a way for the computer to alert the user that the results of the integration may not be reliable.

What causes numerical integration warning to appear?

Numerical integration warning can appear due to several reasons, such as a large number of iterations, a small step size, or a complex function. It can also occur when the integration method is not appropriate for the given function or when the function has sharp changes or discontinuities.

How can I avoid numerical integration warning?

To avoid numerical integration warning, it is important to choose an appropriate integration method for the given function. It is also recommended to use a smaller step size and to check for any potential issues with the function, such as sharp changes or discontinuities. If possible, it is also helpful to choose a simpler function or to break the integration into smaller intervals.

Is numerical integration warning always a cause for concern?

No, numerical integration warning is not always a cause for concern. It is simply a warning that the results of the integration may not be reliable. In some cases, the integration may still produce accurate results, but it is important to be aware of the warning and to consider adjusting the integration method or parameters if necessary.

Can numerical integration warning be ignored?

While numerical integration warning can be ignored, it is not recommended. It is important to pay attention to the warning and to investigate the potential causes. Ignoring the warning may result in inaccurate or unreliable results, which can affect the validity of any conclusions drawn from the integration.

Back
Top