Lesson 3 of 15

Legendre Polynomials

Legendre Polynomials

Legendre polynomials Pn(x)P_n(x) are solutions to Legendre's differential equation and arise naturally in problems with spherical symmetry, such as solving the Laplace equation in spherical coordinates.

Three-Term Recurrence

The polynomials can be generated efficiently using the recurrence relation:

(n+1)Pn+1(x)=(2n+1)xPn(x)nPn1(x)(n+1) P_{n+1}(x) = (2n+1)\, x\, P_n(x) - n\, P_{n-1}(x)

with initial conditions P0(x)=1P_0(x) = 1 and P1(x)=xP_1(x) = x.

The first few polynomials:

  • P0(x)=1P_0(x) = 1
  • P1(x)=xP_1(x) = x
  • P2(x)=12(3x21)P_2(x) = \frac{1}{2}(3x^2 - 1)
  • P3(x)=12(5x33x)P_3(x) = \frac{1}{2}(5x^3 - 3x)
  • P4(x)=18(35x430x2+3)P_4(x) = \frac{1}{8}(35x^4 - 30x^2 + 3)

Orthogonality

Legendre polynomials are orthogonal on [1,1][-1, 1]:

11Pm(x)Pn(x)dx=22n+1δmn\int_{-1}^{1} P_m(x)\, P_n(x)\, dx = \frac{2}{2n+1}\, \delta_{mn}

The normalization constant Pn2=2/(2n+1)\|P_n\|^2 = 2/(2n+1) is returned by legendre_norm(n).

Rodrigues' Formula

An explicit formula using derivatives:

Pn(x)=12nn!dndxn(x21)nP_n(x) = \frac{1}{2^n n!} \frac{d^n}{dx^n} (x^2 - 1)^n

Legendre Series

Any sufficiently smooth function on [1,1][-1, 1] can be expanded in a Legendre series:

f(x)n=0NcnPn(x)f(x) \approx \sum_{n=0}^{N} c_n P_n(x)

The coefficients are cn=2n+1211f(x)Pn(x)dxc_n = \frac{2n+1}{2} \int_{-1}^{1} f(x) P_n(x)\, dx.

Your Task

Implement the three functions below. Use only Python's math module and built-in functions.

Python runtime loading...
Loading...
Click "Run" to execute your code.