function f=plgndr(l,m,x) % return the Ferrer definition of the associated Legendre function. % function f=plgndr(l,m,x) % (c) 2008 Alain Hebert, Ecole Polytechnique de Montreal if m < 0 error('bad arguments in plgndr 1') elseif m > l error('bad arguments in plgndr 2') elseif abs(x) > 1. error('bad arguments in plgndr 3') end pmm=1. ; if m > 0, pmm=prod(1:2:2*m)*sqrt((1.-x).*(1.+x)).^m ; end if l == m f=pmm ; else pmmp1=(2*m+1)*x.*pmm ; if l == m+1 f=pmmp1 ; else for ll=m+2:l pll=((2*ll-1)*x.*pmmp1-(ll+m-1)*pmm)/(ll-m) ; pmm=pmmp1 ; pmmp1=pll ; end f=pll ; end end