I am trying to compute the partial sums of the Legendre polynomials: $\sum_{l \geq 0} P_l(cos \gamma)$ of the first kind. The full sum are known to converge and I wanted to check that the error goes like $1/\sqrt{l}$. I wrote down three ways to compute the first 71 terms in the error. Unexpectedly, one of those (myerror2) takes a long time to compute and furthermore goes completely wild beyond $l \sim 50$. It actually blows up extremely rapidly for larger $l$. The other ones (myerror and myerror3) behave well and expected with the theory. What is going on?
exact[\[Gamma]_] := 1/2 Csc[\[Gamma]/2];
(*Sum[LegendreP[l,Cos[\[Gamma]]],{l,0,Infinity}]*)
my\[Gamma] = Pi/4.2;
myerror[\[Gamma]_] :=
Table[Sum[LegendreP[l, Cos[\[Gamma]]], {l, 0, lmax}], {lmax, 1,
70}] - exact[\[Gamma]];
myerror2 =
Table[Sum[LegendreP[l, Cos[\[Gamma]]], {l, 0, lmax}], {lmax, 1,
70}] - exact[\[Gamma]] /. \[Gamma] -> my\[Gamma];
myerror3 =
Table[Sum[LegendreP[l, Cos[my\[Gamma]]], {l, 0, lmax}], {lmax, 1,
70}] - exact[my\[Gamma]];
Show[ListLogLogPlot[Abs[myerror2], PlotStyle -> Red, PlotMarkers -> "X"],
ListLogLogPlot[Abs[myerror3], PlotStyle -> Black, PlotMarkers -> "<>"],
ListLogLogPlot[Abs[myerror[my\[Gamma]]]],
LogLogPlot[1.5/lmax^(1/2), {lmax, 1, 70}]]
As user Bob Hanlon suggested, using arbitrary-precision, instead of machine precision:
my\[Gamma] = N[10 Pi/42, 15];
allows for myerror2 to coincide with the other result, provided that the precision set is large enough. However, one does not seem to need to do that for myerror and myerror3. Furthermore, the computation time for myerror2 is still noticeably longer than the other two.
myγ = N[10 Pi/42, 15]
$\endgroup$