# Calculation of composite integrals

I am facing trouble calulating the following integrals. Could you give me any advice?

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

Sh[t_] := NIntegrate[-Re[A1[x, t]]*Log[Re[A1[x, t]]], {x, -Infinity, Infinity},
Method -> "DoubleExponential", WorkingPrecision -> 5, AccuracyGoal -> 5, MaxRecursion -> 8]

ShT = Table[{t, Sh[t]}, {t, 0, 10}]

• Can you explain your reasoning behind this choice of options? Method -> "DoubleExponential", WorkingPrecision -> 5, AccuracyGoal -> 5, MaxRecursion -> 8 Nov 15 '21 at 11:02
• @rhermans I tried to define the simplest conditions. There is no specific reason behind them. Nov 15 '21 at 11:14

The following parameter choice will work:

Sh[t_] :=
NIntegrate[-Re[A1[x, t]]*Log[Re[A1[x, t]]], {x, -Infinity, Infinity},
Method -> "DoubleExponential", WorkingPrecision -> 12,
AccuracyGoal -> 5, MaxRecursion -> 12]

ShT = Table[{t, Sh[t]}, {t, 0, 10}]


• Thank you very much! Could you explain why do you choose these conditions for working precision etc.? If I want to form a table for 100 values of "t" and not only 10, what should I do? Nov 15 '21 at 12:27
• I read the error message and then increased the working precision and max. recursion. Nov 15 '21 at 13:56

The following produces the table up to t = 10 in under 7 sec. on my laptop:

u = 0.9;

ClearAll[A, A1];
A[x_, t_] :=
Re[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_] = Simplify[Abs[A[x, t]]^2, {x, t} \[Element] Reals];

Sh[t_] :=
NIntegrate[-A1[x, t]*Log[A1[x, t]], {x, -Infinity, Infinity},
PrecisionGoal -> 5, MaxRecursion -> 20,
Method -> "DoubleExponential"];
ShT = Table[{t, Sh[t]}, {t, 0, 10}]
(*
{{0, 0.937074}, {1, 0.643354}, {2, 1.51625},       {3, -2.7694},
{4, -382.593}, {5, -31421.3}, {6, -4.49781*10^6}, {7, -1.28387*10^9},
{8, -7.67179*10^11}, {9, -9.82327*10^14}, {10, -2.73103*10^18}}
*)


The time increases rapidly with PrecisionGoal. For settings of 4, 5, 6, it takes just under 3, 8, 16 seconds respectively.

With working precision settings other than Automatic or MachinePrecision, arithmetic is done with arbitrary-precision software which uses a 64-bit mantissa for precisions less than \$MachinePrecision $$\approx 15.95$$. Machine precision uses hardware arithmetic which is faster and uses a 53-bit mantissa (normally, these days). Usually one uses WorkingPrecision settings of 16 or higher, unless there is a specific reason for using less. Furthermore, u = 0.9 and N[] convert to machine precision, rendering settings of WorkingPrecision other than Automatic or MachinePrecision rather useless.

MaxRecursion -> 20 was used because I got a NIntegrate::ncvs error, and it allowed NIntegrate to use extra recursion when needed.

The use of N[] and some Re[] are unnecessary, and I removed them. Simplifying A1[] speeds things up a bit.

Remark: Sh[19] didn't finish while I typed this answer.