# Why the animation of a function gives different results from the integral?

My function is:

A1[B_, x_, t_] := (AiryAi[B*(x - (B^3*t^2)/4)])^2


(B is a constant) and if I use "Manipulate" :

BB1[t_] := Plot[Re[A1[1, x, t]], {x, -20, 22}, PlotRange -> {{-20, 22}, {-0.5, 2}}, AxesOrigin
-> {0, 0}, Axes -> None, Frame -> True, FrameTicks -> None, FrameLabel -> {Style["x", Italic],
Row[{"|", Style["\[Psi]", Italic], "(", Style["x", Italic], ")\!$$\*SuperscriptBox[\(|$$, \
(2\)]\)"}]}, AspectRatio -> .25, ImageSize -> {550, 175}]

Manipulate[BB1[t], {{t, 0, "time"}, 0, 5, PerformanceGoal -> "Quality", PlotPoints ->
ControlActive[500, 150], MaxRecursion -> 2,
Appearance -> "Labeled"}]


I can see that this function remains unchanged in form. Therefore, the integral of this function from -Infinity to Infinity should be constant for different values of t. However, when I calculate the integral:

F1[B_, t_] := Re[NIntegrate[A1[B, x, t], {x, -\[Infinity], \[Infinity]}, Method ->
"DoubleExponential", WorkingPrecision -> 20, AccuracyGoal -> 5, MaxRecursion -> 20]]


and then try different values for t (B is a constant and it can be equal to 1), it comes out that F1 is not a constant value. Why does this happen?

• You are not integrating the real part of A1, but A1. Try F1[B_, t_] := NIntegrate[Re[A1[B, x, t]].... Dec 1 '21 at 10:08
• Yes you are right! However, the results are still different. Dec 1 '21 at 10:51
• @ioanna99 With Module this simplified code Module[{}, Manipulate[ {CMax, ProfitRandomization[p, \[Gamma], \[Delta], \[Alpha], CMax]}, {{\[Delta], .317}, 0.01, .9999}, {{\[Alpha], 67.1}, .01, 100}, {{p, 2.62}, .01, 10}, {{\[Gamma], 195.706}, 1, 10000}, {CMax, 0 , 1}, SynchronousUpdating -> False] ] works. Stil don't understand the problems arising with Plot Dec 1 '21 at 11:01

I get this from Integrate:

Integrate[A1[1, x, 0], {x, -\[Infinity], \[Infinity]}]

Integrate::idiv: Integral of AiryAi[x]^2 does not converge on {-\[Infinity],\[Infinity]}.


Another check:

Integrate[A1[1, x, 0], {x, -A, 0}, Assumptions -> A > 0]
Limit[%, A -> Infinity]

(*  A AiryAi[-A]^2 + AiryAiPrime[-A]^2 - 1/(3^(2/3) Gamma[1/3]^2)  *)
(*  \[Infinity]  *)


It seems the integral diverges.

Don't know which problems arise using Plot.

Here a workaround:

First add , MaxIterations -> 1000 in the definition of ProfitRandomization[..., MaxIterations -> 1000]

Second enclose your codee with Module

Third try

Module[{tab},
Manipulate[
tab = Table[{CMax,
ProfitRandomization[p, \[Gamma], \[Delta], \[Alpha],
CMax]}, {CMax, 0 , 1, .1}];
ListPlot[tab]
, {{\[Delta], .317}, 0.01, .9999}, {{\[Alpha], 67.1}, .01,
100}, {{p, 2.62}, .01, 10}, {{\[Gamma], 195.706}, 1, 10000} ,
SynchronousUpdating -> False]]


Code runs quite slow but updates ListPlot as expected.

Hope it helps!