Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.7K Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Is There an Issue with the LegendreP function?

I am trying to evaluate a sum over a large number of terms, each of which includes a Legendre polynomial. At fairly low numbers of the order parameter, I get enormous values for the polynomial.

I have created a simple Notebook to illustrate the issue. You can see that I can plot the Legendre polynomial for orders between 0 and 100

0 and get seemingly sensible answers. If I then do a single call for the final value, I get an error.

I am using MMA 13.2 on a MacBook Pro with Apple silicon.

Any suggestions will be much appreciated.

Thanks, David

Attachments:
POSTED BY: David Mackay
2 Replies
POSTED BY: David Mackay

One way is:

n = 20000;
th = \[Pi]/7;
$MaxExtraPrecision = 10000;(* Increase this value if necessary.*)
N[LegendreP[n, th], 20]
(*-0.0059312818372221032034*)

Second way:

n = 2000000;
th = \[Pi]/7;
LegendrePPP[n_, z_] := (1/Pi) NIntegrate[(z - Sqrt[z^2 - 1] Cos[t])^n, {t, 0, Pi}, 
   WorkingPrecision -> 30, MaxRecursion -> 20]
LegendrePPP[n, th]

(*0.000475301944163975616743822092080*)

Third way is the best it's very fast:

 ClearAll["`*"]; Remove["`*"];
 S[n_, z_] = (Series[LegendreP[n, z], {n, Infinity, 1}] // Normal // Simplify)
 n = 10000000;(* Try: n = 10^100 *)
 th = \[Pi]/7;
 N[S[n, th], 20]
 (*-0.00018112363719941377947*)
POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard