This is not a bug. It's an improvement. The integral is divergent.
The V5 Oscillatory
method is defunct. NIntegrate
chooses the "ExtrapolatingOscillatory"
method (which is the method it chooses for this integral if Method -> Automatic
). This method checks convergence, and the amplitude of the oscillations goes to infinity. Therefore you cannot apply this method. Whether or not one can make sense of the integral or series used in the extrapolating oscillatory method by applying methods for divergent series, I did not look further into. The nice shape of the graph suggests something like Euler's approach to $\sum (-1)^n n!x^{n+1}$ might be possible.
Analytic divergence.
Let's define the integrand two ways, the original machine-precision one as integrand0
and the rationalized, exact one as integrand
.
integrand = Rationalize[
Rationalize[
integrand0 =
BesselJ[0, y]/Sqrt[(y^2 + w^2)^3]*1/
d*(Erfc[(p*10^-15 - 1)/Sqrt[2]])*
Exp[(p*10^-15)^2/2 - p*10^-15*(1 - τ)]*y*w
],
0];
The aymptotic expansion of BesselJ[0, y]
has a leading term proportional to 1/Sqrt[y]
:
Normal@Series[BesselJ[0, y], {y, Infinity, 0}]
(* (Sqrt[2/π] Cos[π/4 - y])/Sqrt[y] *)
To check convergence, the "ExtrapolatingOscillatory"
strategy replaces BesselJ[0, y]
by 1/Sqrt[y]
and takes the limit at infinity. This results in ComplexInfinity
, even if τ
does not have a numeric value:
Limit[integrand0 /. _BesselJ -> 1/Sqrt[y], y -> Infinity]
(* ComplexInfinity *)
Limit[integrand /. _BesselJ -> 1/Sqrt[y], y -> Infinity,
Assumptions -> τ > 0]
(* Infinity *)
(The exact limit is difficult for Limit
to evaluate without some helpful assumption about τ
.) We can see the actual limit use in the following trace:
ClearSystemCache[] (* Asymptotics`ClassicLimit caches some results *)
Trace[
10^18*Sqrt[π/2]*
NIntegrate[
BesselJ[0, y]/Sqrt[(y^2 + w^2)^3]*1/
d*(Erfc[(p*10^-15 - 1)/Sqrt[2]])*
Exp[(p*10^-15)^2/2 - p*10^-15*(1 - τ)]*y*w,
{y, 0, ∞},
Method -> Oscillatory,(* defunct method *)
MaxRecursion -> 12],
_Asymptotics`ClassicLimit,
TraceInternal -> True, TraceForward -> True] /.
x_Times /; Simplify[x - integrand0 /. _BesselJ -> 1/Sqrt[y]] == 0 ->
"integrand0"
Numerical divgence 1.
We've seen that things in Mathematica can go wrong, so we should look for further verification.
Here is an evaluation of the integrand at increasing powers of 2
.
Block[{τ = 1000},
integrand /. y -> N[2^Range@14, 16] // RealExponent
]
(*
{-17.3277, -18.4065, -23.9926, -44.2635, -124.654, -444.958,
-1723.93, -6791.65, -26461., -95463.2, -216725., 1.77412*10^6,
4.93517*10^7, 8.7349*10^8}
*)
Note these are the exponents (base $10$).
Initially, the integrand seems to converge very rapidly to zero (down to $10^{-216725}$). This is why NIntegrate
misses the divergence in Plot
: Plot
applies N
to NIntegrate
when it first returns unevaluated, and N[NIntegate[..]]
somehow forces the fall-back method of the "ExtrapolatingOscillatory"
strategy, which by default is "GlobalAdaptive"
with "GaussKronrodRule"
. The "GaussKronrodRule"
fails to detect divergence for smaller values of τ
because it samples only in the apparently-convergence part of the domain.
However, it can be seen that the amplitude takes off, reaching $10^{10^8}$ at $y = 16384$.
Numerical divergence 2.
As another confirmation, we can modify @xzczd's implementation of the extrapolating oscillatory method. We add NSumTerms -> 100
:
int[f_, t_?NumericQ, prec_ : MachinePrecision] :=
NSum[separateint[f, t, i, prec], {i, 0, Infinity}, Method -> "AlternatingSigns",
NSumTerms -> 100
WorkingPrecision -> prec];
Then we get a much different result:
T /. τ -> 1
(* 2.09192*10^153 *)
My original answer is only partly right, but using a proper definition turned out to be a minor side issue. Here's an easier way to get plot of the "value" of the integral. Erelyi's approach to Euler's sum for $\sum (-1)^n n!x^{n+1}$ in Asymptotic Expansions is to observe that for small $x$, "the terms of the series at first decrease quite rapidly, and an approximate numerical value of [the sum] may be computed." Likewise we can truncate the interval of integration near the minimum amplitude and cut off the divergent part. No analysis has been made of whether this value can be considered equivalent to the integral, whether in the sense of Euler's paper or in some other way.
ClearAll[T];
T[τ0_?NumericQ] :=
Block[{τ = SetPrecision[τ0, Infinity]},
10^18*Sqrt[π/2]*NIntegrate[integrand,
Evaluate@{y, 0,
Max[15, First@
FindArgMin[
integrand /. _BesselJ -> 1/Sqrt[y], {y, 50 + τ, 0,
10000}, WorkingPrecision -> 25]
]}, MaxRecursion -> 12]
];
Plot[T[τ1], {τ1, 0, 6*10^3},
MaxRecursion -> 1] // AbsoluteTiming
Original answer
The problem (for V12.1.1) is that T
is not properly defined. Making it a function of τ
gets rid of all error/warning messages:
ClearAll[T];
T[τ_?NumericQ] :=
10^18*Sqrt[π/2]*
NIntegrate[
BesselJ[0, y]/Sqrt[(y^2 + w^2)^3]*1/
d*(Erfc[(p*10^-15 - 1)/Sqrt[2]])*
Exp[(p*10^-15)^2/2 - p*10^-15*(1 - τ)]*y*w,
{y, 0, ∞}, MaxRecursion -> 12];
Plot[T[τ], {τ, 0, 6*10^3},
MaxRecursion -> 1] // AbsoluteTiming
p2
write insteadSubscript[p, 2]
$\endgroup$Yes it works in V5
how could numerical integral work when there is undefined symbol (in your case $\tau$) inside it, other than the integration variable? This makes little sense to me as numerical integration needs numerical values for all parameters. Could you show screen shot, from clean kernel showing it works? This will help clarify things. $\endgroup$