# Numerical Integration warning

• MATLAB
• EngWiPy
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?

#### EngWiPy

Hi,

I am trying to evaluate the following integral numerically in MATLAB

$$\int_0^{\infty}\frac{e^{-jt}E_1^2(-jt)}{t}\,dt$$

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

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.

EngWiPy said:
Hi,

I am trying to evaluate the following integral numerically in MATLAB

$$\int_0^{\infty}\frac{e^{-jt}E_1^2(-jt)}{t}\,dt$$

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##.

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?

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.

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

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

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

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

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##.

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.

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:
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:
[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.]

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?

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.

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.

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?

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.

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##.

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

$$\nu=\sum_{k=1}^K\frac{a_k}{b_k}$$

where ##\{a_k, b_k\}## are i.i.d. exponential random variables with parameter 1.

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

$$\nu=\sum_{k=1}^K\frac{a_k}{b_k}$$

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?

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.

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.

tnich 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?

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.

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.

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.

jim mcnamara
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.