MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

LegendreP Evaluation Mystery


Dear all,

I have found that Mathematica v5.2 evaluates BesselJ and LegendreP
differently. Why is this? I have written this test below to illustrate
the timing.

In[11]:=
k=10000;
n=51;
m=Random[Integer,{0,n}];
x=Random[Real,{0,1}];
P[y_]=LegendreP[n,m,y];
J[y_]=BesselJ[n,y];
Timing[Do[LegendreP[n,m,x],{k}]]
Timing[Do[P[x],{k}]]
Timing[Do[BesselJ[n,x],{k}]]
Timing[Do[J[x],{k}]]

Out[17]=
{4.531 Second,Null}

Out[18]=
{0.484 Second,Null}

Out[19]=
{0.61 Second,Null}

Out[20]=
{0.657 Second,Null}

The emphasis here is with the Associated Legendre Function, since it is
a bottel neck of my current calculations for big n's (n>50), used
inside NIntegrate. The form LegendreP[n,m,x] takes longer to evaluate
than in extended form (P[y])? If I try to use the extended form to do
some numerical integration, it results in a wrong result even though
it is faster.

When plotting the functions, it seems to show some numerical
instabilities (for low m):

n = 51; m = 3;
Plot[LegendreP[n, m, x], {x, 0, 1}, PlotRange -> All, PlotPoints ->
100];
Plot[P[x], {x, 0, 1}, PlotRange -> All, PlotPoints -> 100];

And it is worse for m=0. Does Mathematica evaluate LegendreP
differently for high n's, why does it take so long? Is there any way
that I build an array of extended Associated Legendre functions, so as
to speed up calculations and wouldn't fail numerically as above?

Antonio



  • Prev by Date: Re: 2D cellular automata (non-totalistic)
  • Next by Date: Re: Differentiation and evaluation of function
  • Previous by thread: Mathematica SIG (Northern Virginia and Washington DC)
  • Next by thread: Re: LegendreP Evaluation Mystery