What is happening near 0 when I plot the function LerchPhi
?
Plot[LerchPhi[y^2, 1, 9/2], {y, -1, 1}]
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityThe problem here, as already noted by Mariusz, is that severe cancellation is happening when evaluating near the origin.
A solution in this case is to use a different representation of your function in terms of Hypergeometric2F1[]
, which performs better for tiny arguments:
Plot[2/9 Hypergeometric2F1[1, 9/2, 11/2, y^2], {y, -1, 1}]
LerchPhi
doesn't simply call Hypergeometric2F1
for numerical evaluation?
$\endgroup$
Nov 14, 2017 at 14:31
HurwitzLerchPhi[]
.
$\endgroup$
Nov 14, 2017 at 14:37
"but what if I needs its value for computing?"
LerchPhi[y^2, 1, 9/2]
(* (-2 - (2*y^2)/3 - (2*y^4)/5 -
(2*y^6)/7 + (2*ArcTanh[y])/y)/y^8 *)
LerchPhi[0, 1, 9/2]
(* 2/9 *)
With machine precision near zero you get a bad result
LerchPhi[0.0001, 1., 4.5]
(* 0. *)
Using arbitrary precision
LerchPhi @@ SetPrecision[{0.0001, 1., 4.5}, 20]
(* 0.22 *)
Precision[%]
(* 1.60341 *)
Almost all precision is lost between input and output. It is much better to convert input to exact numbers and then convert exact output to numeric values
N[LerchPhi @@ ({0.0001, 1., 4.5} // Rationalize), 20]
(* 0.22224040557899892396 *)
Precision[%]
(* 20. *)
Plot[{LerchPhi[y^2, 1, 9/2]}, {y, -1, 1}, WorkingPrecision -> 100, PlotRange -> {Automatic, {0, 1}}]
$\endgroup$