# How do I avoid the singularities during the calculation of an integral?

I face a serious problem when I try to calculate the following integral. My code is the following:

u = 0.9;

A[x_, t_] := Re[N[AiryAi[x - u*t + I*u*t - t^2]]*Exp[I*t (x - u*t - t^2 + u/2)]*
Exp[x - u*t - t^2]*Exp[I*(x - u*t)]]

A1[x_, t_] := A[x, t]* Conjugate[A[x, t]]

F[t_]:= NIntegrate[(D[Re[A1[x, t]], x])^2/Re[A1[x, t]], {x, -Infinity, Infinity},
Method -> "DoubleExponential"]

F[#] & /@ Range[0, 10];


Could anyone tell me how to overcome the warning messages?

• are you sure you want to integrate from infinity to infinity? Would not this always give 0? In addition, you are doing numerical integration w.r.t. $x$, but there is a free variable $t$ in there. Nov 24 at 14:38
• @Nasser I am sorry. I meant "from -Infinity to Infinity". The integral is a function of t. Nov 24 at 14:58
• I thought that is what you meant, but the function you are integrating has non-numerical value $t$ in it. Hence not possible to do numerical integration, If you look at the integrand you will see this. So you need to give $t$ some numerical value before. Nov 24 at 15:02
• @Nasser However, if I use the Real part (Re[...]) of the integrand, then I can do numerical integration, right? Nov 24 at 15:13
• Another problem: you are taking the derivative of a function involving Re, which isn't analytic. Have a look at the nonsense D[Re[A1[x, t]], x] yields. Nov 24 at 16:20

I'd recommend going as far as possible with analytic calculations and only using numerics at the end. Especially numerical derivatives are notoriously difficult to calculate exactly.

Define the function $$A$$ without numerics:

A[u_, x_, t_] = AiryAi[x - u*t + I*u*t - t^2] * Exp[I*t (x - u*t - t^2 + u/2)] * Exp[x - u*t - t^2]*Exp[I*(x - u*t)];


Define its complex conjugate manually by replacing every I with -I (see elsewhere for details):

Ac[u_, x_, t_] = AiryAi[x - u*t - I*u*t - t^2] * Exp[-I*t (x - u*t - t^2 + u/2)] * Exp[x - u*t - t^2]*Exp[-I*(x - u*t)];


Define $$|A|^2$$ without using the Re operator:

A1[u_, x_, t_] = A[u, x, t]*Ac[u, x, t];


Define the integrand through analytic differentiation:

B[u_, x_, t_] = D[A1[u, x, t], x]^2/A1[u, x, t] // Simplify;


Now we can integrate without problems. Using Re to chop off very small imaginary parts (on the order of the machine precision),

Clear[F];
F[u_?NumericQ, t_?NumericQ] := F[u, t] =
Re[NIntegrate[B[u, x, t], {x, -∞, 0, t^2, ∞}]]


where I've added the intermediate integration points $$x=0$$ and $$x=t^2$$ so that NIntegrate is more stable; they were roughly estimated from plotting some examples of $$B(u,x,t)$$ and could be improved for better speed.

Check:

ListLogPlot[Table[{t, F[9/10, t]}, {t, 0, 10}], Joined -> True]


• Thank you very much for the detailed answer. Could you explain the necessity of using "?NumericQ" in the argument of function F ? Nov 25 at 14:52
• It's not necessary but ensures that the user does not abuse F. For example, asking for F[a, b] will not attempt any numerical integration work because a and b aren't numerical and the integration would fail anyway. Nov 25 at 14:56
• Thank you very much! Do you have any idea why the results are different for F[9/10, t] and F[0.9, t] ? Dec 2 at 21:11