Legendre & Orthogonal Polynomials

Legendre, Chebyshev, Hermite and Laguerre polynomials are families that are mutually orthogonal under a weighted inner product. Learn their generating equations, Rodrigues' formula, recurrences, orthogonality integrals, and why they power Gaussian quadrature, least-squares fitting, spectral methods, spherical potentials and quantum mechanics.

Just as the vectors î, ĵ, k̂ are perpendicular, certain polynomial families are 'perpendicular' in the sense that the integral of their product is zero. That makes them ideal basis functions: coefficients can be found one at a time, and truncating the series gives the best approximation.

Legendre polynomials appear when solving Laplace's equation in spherical coordinates (gravitational and electric potentials), and their roots give the nodes of Gauss–Legendre quadrature — the integration rule inside nearly every finite-element code.

An analogy

Orthogonal polynomials are like the independent sliders of a graphic equaliser: moving one does not disturb the others, so you can tune each component of a function separately.

What 'orthogonal functions' means

For vectors, orthogonal means a·b = 0. For functions, the dot product becomes an integral: ⟨f, g⟩ = ∫ f g w dx. Two functions are orthogonal if that integral is zero. sin x and sin 2x on [0, π] are orthogonal; so are P₂ and P₃ on [−1, 1].

The main families

Each family is orthogonal on its own interval with its own weight — pick the one matching your problem's domain.

Best approximation

Truncating f = Σ aₙPₙ after N terms gives the least-squares-best polynomial of degree N. Chebyshev truncation is nearly minimax (smallest maximum error), avoiding the Runge oscillations of equally-spaced interpolation — which is why Chebyshev nodes are used for interpolation.

Sturm–Liouville origin and Gaussian quadrature

All these families are eigenfunctions of Sturm–Liouville problems, which guarantees orthogonality and completeness. Placing n quadrature points at the roots of the n-th orthogonal polynomial makes the rule exact for polynomials of degree 2n − 1 — double what n arbitrary points can achieve.

Spectral methods in CFD expand the solution in Chebyshev or Legendre polynomials, giving exponential convergence for smooth problems.

Formulas

Worked example: Rodrigues' formula

Given: n = 2

Find: P₂(x).

Answer: P₂ = (3x² − 1)/2

Worked example: Gauss 2-point rule is exact for cubics

Given: ∫₋₁¹ (x³ + x²) dx, nodes ±1/√3, weights 1

Find: Compare with exact.

Answer: Both give 0.6667 — exact.

Worked example: Legendre expansion

Given: f(x) = x² on [−1, 1]

Find: Expansion in Pₙ.

Answer: x² = ⅓P₀ + ⅔P₂

Gauss–Legendre quadrature and orthogonality

import numpy as np

f = lambda x: np.cos(x)
exact = 2 * np.sin(1)
for n in (1, 2, 3, 4):
    x, w = np.polynomial.legendre.leggauss(n)   # nodes = roots of P_n
    I = np.sum(w * f(x))
    print(f"n={n}: nodes={np.round(x, 4)}  I={I:.8f}  error={abs(I - exact):.1e}")

# Orthogonality check: integral of P2*P3 and P3*P3 on [-1, 1]
P2 = np.polynomial.legendre.Legendre.basis(2)
P3 = np.polynomial.legendre.Legendre.basis(3)
print("int P2*P3 =", round((P2 * P3).integ()(1) - (P2 * P3).integ()(-1), 10))
print("int P3*P3 =", round((P3 * P3).integ()(1) - (P3 * P3).integ()(-1), 6), " (2/7 =", round(2/7, 6), ")")
# n=1: nodes=[0.]  I=2.00000000  error=3.2e-01
# n=2: nodes=[-0.5774  0.5774]  I=1.67582366  error=7.1e-03
# n=3: nodes=[-0.7746  0.      0.7746]  I=1.68300355  error=6.2e-05
# n=4: nodes=[-0.8611 -0.34    0.34    0.8611]  I=1.68294169  error=2.8e-07
# int P2*P3 = 0.0
# int P3*P3 = 0.285714  (2/7 = 0.285714 )

With just 4 function evaluations Gauss–Legendre reaches 10⁻⁷ accuracy — Simpson's rule would need about 40. This is why FEM element integrals use Gauss points.

Common mistakes

Applications

Key takeaways

Going further