1
$\begingroup$

What is happening near 0 when I plot the function LerchPhi?

Plot[LerchPhi[y^2, 1, 9/2], {y, -1, 1}]

bad plot

$\endgroup$
3
  • 2
    $\begingroup$ Possible a numeric noise,try Plot[{LerchPhi[y^2, 1, 9/2]}, {y, -1, 1}, WorkingPrecision -> 100, PlotRange -> {Automatic, {0, 1}}] $\endgroup$ Oct 17, 2017 at 11:22
  • 1
    $\begingroup$ Please don't use the bugs tag when posting new questions. See the tag description. $\endgroup$
    – Szabolcs
    Oct 17, 2017 at 13:42
  • $\begingroup$ many thanks, but what if I needs its value for computing? $\endgroup$
    – eradi
    Oct 17, 2017 at 16:39

2 Answers 2

3
$\begingroup$

The 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}]

plot of function

$\endgroup$
2
  • $\begingroup$ May I ask why, under-the-hood, LerchPhi doesn't simply call Hypergeometric2F1 for numerical evaluation? $\endgroup$
    – QuantumDot
    Nov 14, 2017 at 14:31
  • $\begingroup$ I don't know either, honestly. (Probably a good suggestion to send to support.) Note that the same problem happens with HurwitzLerchPhi[]. $\endgroup$ Nov 14, 2017 at 14:37
0
$\begingroup$

"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. *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.