
Both the Legendre polynomials and the shifted Legendre polynomials are programmed. The first type, the classical Legendre polynomials, denoted by P_{n}, are orthogonal on the support interval [1, 1] with weight function w(x) =  0  for x ≤ 1  1  for 1 < x < 1  0  for x ≥ 1 


and normalized by the requirement that P_{n}(1) = 1.
The second type, the shifted Legendre polynomials, denoted by P_{n}^{*}, are orthogonal on the support interval [0, 1] with weight function w(x) =  0  for x ≤ 0  1  for 0 < x < 1  0  for x ≥ 1 


and normalized by the requirement that P_{n}^{*}(1) = 1.
The classical form, P_{n}, satisfies the threeterm recurrence relation (n+1) P_{n+1}(x) = (2n + 1)x P_{n}(x)  n P_{n1}(x)  for n ≥ 1 

with starting values P_{0}(x) = 1,  P_{1}(x) = x. 

While the shifted form, P_{n}^{*}, satisfies the threeterm recurrence relation (n + 1) P_{n+1}^{*}(x) = (2n + 1) (2x  1) P_{n}^{*}(x)  n P_{n1}^{*}(x)  for n ≥ 1 

with starting values P_{0}^{*}(x) = 1,  P_{1}^{*}(x) = 2 x  1. 

 double Legendre_Pn( double x, int n )
This function returns P_{n}(x) where P_{n}(x) is described above.
 long double xLegendre_Pn( long double x, int n )
This function returns P_{n}(x) where P_{n}(x) is described above.
 void Legendre_Pn_Sequence( double P[ ], double x, int max_n )
This function returns P_{n}(x), for n = 0, 1, …, max_n in the array P[ ] where P_{n}(x) is described above. Note that P[ ] should be declared as double P[N] where N ≥ max_n + 1._{ }
 void xLegendre_Pn_Sequence( long double P[ ], long double x, int max_n )
This function returns P_{n}(x), for n = 0, 1, …, max_n in the array P[ ] where P_{n}(x) is described above. Note that P[ ] should be declared as long double P[N] where N ≥ max_n + 1._{ }
 double Legendre_Pn_Series( double x, double a[ ], int degree)
This function returns Σ_{k=0}^{n}a[k] P_{k}(x) where n = degree and P_{k}(x) for k = 0, …, n is described above._{ }
 long double xLegendre_Pn_Series( long double x, long double a[ ], int degree )
This function returns Σ_{k=0}^{n}a[k] P_{k}(x) where n = degree and P_{k}(x) for k = 0, …, n is described above._{ }
 double Legendre_Shifted_Pn( double x, int n )
This function returns P_{n}^{*}(x) where P_{n}^{*}(x) is described above.
 long double xLegendre_Shifted_Pn( long double x, int n)
This function returns P_{n}^{*}(x) where P_{n}^{*}(x) is described above.
 void Legendre_Shifted_Pn_Sequence( double P[ ], double x, int max_n )
This function returns P_{n}^{*}(x), for n = 0, 1, …, max_n in the array P[ ] where P_{n}^{*}(x) is described above. Note that P[ ] should be declared as double P[N] where N ≥ max_n + 1._{ }
 void xLegendre_Shifted_Pn_Sequence( long double P[ ], long double x, int max_n )
This function returns P_{n}^{*}(x), for n = 0, 1, …, max_n in the array P[ ] where P_{n}^{*}(x) is described above. Note that P[ ] should be declared as long double P[N] where N ≥ max_n + 1._{ }
 double Legendre_Shifted_Pn_Series( double x, double a[ ], int degree )
This function returns Σ_{k=0}^{n}a[k] P_{k}^{*}(x) where n = degree and P_{k}^{*}(x) for k = 0, …, n is described above._{ }
 long double xLegendre_Shifted_Pn_Series( long double x, long double a[ ], int degree )
This function returns Σ_{k=0}^{n}a[k] P_{k}^{*}(x) where n = degree and P_{k}^{*}(x) for k = 0, …, n is described above._{ }
C source code is available for these routines:
