Legendre Polynomials

Welcome to the wonderful world of Legendre Polynomials!!

For this part of the help file I will give you the code that I used to program the Legendre section of my program. Dont get too exited yet, because first Iím going to give credit where credit is due:

Numerical Recipes in Pascal

Chapter 6.6 on Spherical Harmonics,

also p. 712 for the Pascal Code.

Here is the code:

Function plgndr(l,m: integer; x:real) :real;

var

fact, pll, pmm, pmmp1,somx2: real;

i, ll: integer;

begin

If ((m<0) or (m>1) or (abs(x) > 1.0)) then

begin

MessageDlg('Not Within Current Range',mtError,[mbOk],0);

end;

pmm:=1.0 ;

if (m>0) then

begin

somx2:=sqrt((1.0-x)*(1.0+x));

fact:=1.0;

for i := 1 to m do

begin

pmm:= -pmm*fact*somx2;

fact:= fact+2.0;

end;

end;

if (l=m) then

begin

plgndr :=pmm;

end

else

begin

pmmp1:= x*(2*m+1)*pmm;

If (1 =m+1 ) then

begin

plgndr :=pmmp1;

end

else

begin

for ll := m+2 to 1 do

begin

pll := (x*(2*ll-1)*pmmp1-(ll+m-1)*pmm)/(ll-m);

pmm := pmmp1;

pmmp1:= pll;

end;

plgndr := pll;

end;

end;

end;