Chi-Tech
assoc_legendrepoly.cc
Go to the documentation of this file.
1#include "legendrepoly.h"
2#include <cmath>
3#include <cstdlib>
4
5//###################################################################
6/**Provides the function evaluation of the associated Legendre polynomial at value x.
7
8
9This code has a whitepaper associated with it
10<a href="SphericalHarmonics.pdf" target="_blank"><b>Spherical Harmonics</b></a>
11
12
13 \param ell int The ell order of the polynomial.
14 \param m int The m-th moment of the polynomial
15 \param x double The evaluation point.*/
16double chi_math::AssocLegendre(unsigned int ell, int m, double x)
17{
18 if (abs(m)>ell) return 0.0;
19
20 //===== ell=0, m=0
21 if (ell==0) return 1.0;
22
23
24
25 //===== ell=1, m=0,
26 double Pn = x;
27
28 //===== ell=1, m=1
29 double Pnpos = -sqrt(1.0 - x*x);
30
31 if (ell==1)
32 {
33 if (m== 0) return Pn;
34 if (m== 1) return Pnpos;
35 }
36
37 double Pmlp1;
38 if (ell==m)
39 {
40 Pmlp1 = -(2.0*ell-1.0)*sqrt(1.0 - x*x) *
41 AssocLegendre(ell-1,int(ell)-1,x);
42 }
43 else
44 {
45 Pmlp1 = (2.0*ell-1.0)*x*AssocLegendre(ell-1,m,x);
46 Pmlp1 = Pmlp1 - (ell+m-1)*AssocLegendre(ell-2,m,x);
47 Pmlp1 = Pmlp1 / (ell-m);
48 }
49
50 return Pmlp1;
51}
double AssocLegendre(unsigned int ell, int m, double x)