"After multiplying the integrand of NIntegrate
with -1
, the Precision
of the output will change." ← Sounds silly, huh? But this seems to be true at least for numerical integral internally using "ExtrapolatingOscillatory"
method. Just try the following example:
Precision /@
NIntegrate[{1, -1} BesselJ[0, x], {x, 0, ∞}, WorkingPrecision -> 32,
Method -> "ExtrapolatingOscillatory"]
{31.0265, 25.0279}
It's not necessary to set Method -> "ExtrapolatingOscillatory"
manually in this sample, I added the option just to emphasize.
Of course in the above example the difference of precision is small and isn't a big deal, but in some cases the difference can be drastic, for example the following I encountered in this problem:
f[p_, ξ_] = -(5 p Sqrt[(5 p^2)/6 + ξ^2] )/(
4 (-4 ξ^2 Sqrt[(5 p^2)/6 + ξ^2] Sqrt[(5 p^2)/2 + ξ^2] + ((5 p^2)/2 + 2 ξ^2)^2));
pmhankel[p_, sign_: 1, prec_: 32] :=
NIntegrate[sign ξ BesselJ[0, ξ] f[p, ξ], {ξ, 0, ∞},
WorkingPrecision -> prec, Method -> "ExtrapolatingOscillatory"]
preclst = Table[Precision@pmhankel[#, sign] & /@ Range@32, {sign, {1, -1}}]
ListLinePlot[preclst, PlotRange -> All]
It's not necessary to set Method -> "ExtrapolatingOscillatory"
manually in this sample, I added the option just to emphasize.
How to understand the behavior? Except for calculating every integral twice and choosing the better one, how to circumvent the problem?
Answer
The oddity in this case comes from NSum
which is being called in a certain way from NIntegrate
. This is a simple example that has roughly the same behavior (note in this case the exact result is known to be $\mp \ln 2$):
NSum[(-1)^n/n, {n, 1, Infinity},
Method -> {"AlternatingSigns", Method -> "WynnEpsilon"}, WorkingPrecision -> 32]
(* -0.6931471805599453094172318803247 *)
NSum[-(-1)^n/n, {n, 1, Infinity},
Method -> {"AlternatingSigns", Method -> "WynnEpsilon"}, WorkingPrecision -> 32]
(* 0.693147180559945309417232 *)
where the second result has several digits fewer than the first.
Is that a bug? Not necessarily, because both results have at least 16 correct digits which certainly attains the default PrecisionGoal
, which is WorkingPrecision/2
.
Still, I agree the consistency could be improved in this case and I have filed a report for the developers to take a look.
Update
This has been improved in the just released Mathematica 11.0.
Comments
Post a Comment