MATLAB: Associated legendre polynomials fail after certain degree

legendreprecision

Hi,
I am using legendre polynomials for an application on spherical harmonics. However the code
legendre(170,0.5)
where 170 is the degree/order fail, giving me Inf or NaN. Is this considered a bug or is there way to aid the issue using higher precision somehow?
Best

Best Answer

Hi ailbeildce,
Try legendre(n,x,'norm') or legendre(n,x,'sch'). Each of these normalizes the associated legendre function slightly differently, and both leave out a factor in front that gets out of hand in a big way as m gets large [where m is the upper parameter in Pmn, 0<=m<=n, and m=0 corresponds to the usual Pn].
With either of those options, n can go up to at least 2400.
You can see what the factors are in 'doc legendre'. You will have to check, but I think the 'norm' option for Pmn gives you
Int{-1,1} Pmn(x)^2 dx = 1,
appropriate for spherical harmonics.