Bug introduced in 7.0 or earlier and fixed in 11.0
This is a follow-up to this question regarding numerical instabilities occurring with modified Bessel functions. In trying to explore J.M.'s answer to that question in greater depth by setting WorkingPrecision -> 50
(as advised in the other answer by xslittlegrass), I obtained vastly different (and incorrect!) results than when not explicitly setting a non-default WorkingPrecision
(see below for plots). I am trying to figure out why this is occurring and was advised to make a separate question regarding this.
The function that I am attempting to plot (for fixed $b$, as a function of $a$) is
f[a_, b_] := (a^2 Exp[a^2/(8 b)] (BesselK[3/4, a^2/(8 b)] -
BesselK[1/4, a^2/(8 b)]))/(8 Sqrt[a b^3])
which is the analytic solution to
Integrate[x^2 Exp[-a x^2 - b x^4], {x, -∞, ∞}, Assumptions -> {a > 0, b > 0}]
I also plot the numerical solution to this,
g[a_,b_] := NIntegrate[x^2 Exp[-a x^2 - b x^4], {x, -∞, ∞}]
Without any regards to WorkingPrecision
, I obtain the following plot:
amin = 10^-10; amax = 0.1; bval = 10^-3;
LogLogPlot[{f[a, bval], g[a, bval]}, {a, amin, amax}, PlotRange -> All]
Even with explicitly giving the variable/bounds higher precision,
amin = 1`50 10^-10; amax = 0.1`50; bval = 1`50 10^-3;
the plot remains the same as above. If, however, I add in WorkingPrecision -> 50
, a plot with function values many orders of magnitude higher is obtained:
amin = 1`50 10^-10; amax = 0.1`50; bval = 1`50 10^-3;
LogLogPlot[{f[a, bval], g[a, bval]}, {a, amin, amax}, WorkingPrecision -> 50,
PlotRange -> All]
The fact that this is occurring is worrisome, as I would generally expect the results obtained with higher WorkingPrecision
to be more trustworthy; in this case, however, they are completely wrong -- here's a representative plot:
bval = 10^-3;
Plot[x^2 Exp[-a x^2 - bval x^4] /. a -> 10^-5, {x, -15, 15}]
Why is this happening? Thank you very much!
Integrate
instead ofNIntegrate
in your definition ofg
? $\endgroup$NIntegrate[]
, @bb; he was comparing the solution I derived in the other thread with the results of numerical integration. $\endgroup$Assumptions
is not a legal option forNIntegrate
. $\endgroup$