Legendre Polynomials



Legendre Polynomials
Both the Legendre polynomials and the shifted Legendre polynomials are programmed. The first type, the classical Legendre polynomials, denoted by Pn, are orthogonal on the support interval [-1, 1] with weight function
w(x) =
0for x ≤ -1
1 for -1 < x < 1
0for x ≥ 1
and normalized by the requirement that Pn(1) = 1.
The second type, the shifted Legendre polynomials, denoted by Pn*, are orthogonal on the support interval [0, 1] with weight function
w(x) =
0for x ≤ 0
1 for 0 < x < 1
0for x ≥ 1
and normalized by the requirement that Pn*(1) = 1.

The classical form, Pn, satisfies the three-term recurrence relation
(n+1) Pn+1(x) = (2n + 1)x Pn(x) - n Pn-1(x)for n ≥ 1
with starting values
P0(x) = 1, P1(x) = x.

While the shifted form, Pn*, satisfies the three-term recurrence relation
(n + 1) Pn+1*(x) = (2n + 1) (2x - 1) Pn*(x) - n Pn-1*(x)for n ≥ 1
with starting values
P0*(x) = 1, P1*(x) = 2 x - 1.

Function List

  • double Legendre_Pn( double x, int n )

    This function returns Pn(x) where Pn(x) is described above.

  • long double xLegendre_Pn( long double x, int n )

    This function returns Pn(x) where Pn(x) is described above.

  • void Legendre_Pn_Sequence( double P[ ], double x, int max_n )

    This function returns Pn(x), for n = 0, 1, …, max_n in the array P[ ] where Pn(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 Pn(x), for n = 0, 1, …, max_n in the array P[ ] where Pn(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=0na[k] Pk(x) where n = degree and Pk(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=0na[k] Pk(x) where n = degree and Pk(x) for k = 0, …, n is described above.

  • double Legendre_Shifted_Pn( double x, int n )

    This function returns Pn*(x) where Pn*(x) is described above.

  • long double xLegendre_Shifted_Pn( long double x, int n)

    This function returns Pn*(x) where Pn*(x) is described above.

  • void Legendre_Shifted_Pn_Sequence( double P[ ], double x, int max_n )

    This function returns Pn*(x), for n = 0, 1, …, max_n in the array P[ ] where Pn*(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 Pn*(x), for n = 0, 1, …, max_n in the array P[ ] where Pn*(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=0na[k] Pk*(x) where n = degree and Pk*(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=0na[k] Pk*(x) where n = degree and Pk*(x) for k = 0, …, n is described above.

Source Code

C source code is available for these routines: