TExcelTAD
Home › Differential Equations › Bessel and Legendre Functions

Bessel and Legendre Functions

Separating variables in the heat, wave or Laplace equation on a disc, a cylinder or a sphere (Fourier Series and PDEs) leads to two variable-coefficient equations so often that their solutions have names. Bessel functions describe vibrating drums and heat in cylinders; Legendre polynomials describe fields on a sphere. Both are computed in SciPy.

Bessel's equation

x2y′′+xy′+(x2−ν2) y=0.x^2y'' + xy' + (x^2 - \nu^2)\,y = 0.

x=0x = 0 is a regular singular point with indicial roots ±ν\pm\nu (Frobenius Method). The Frobenius series for r=νr = \nu gives the Bessel function of the first kind

Jν(x)=∑k=0∞(−1)kk! Γ(k+ν+1)(x2)2k+ν.J_\nu(x) = \sum_{k=0}^\infty \frac{(-1)^k}{k!\,\Gamma(k + \nu + 1)}\left(\frac{x}{2}\right)^{2k + \nu}.

For integer ν=n\nu = n, the second solution Yn(x)Y_n(x) (second kind) contains ln⁡x\ln x and blows up at 0. Physically meaningful solutions that stay finite at the centre use only JnJ_n.

python · try it yourself
import math
from scipy.special import jv, yv

def J_series(nu, x, terms=30):
    return sum((-1)**k / (math.factorial(k) * math.gamma(k + nu + 1)) * (x / 2)**(2*k + nu) for k in range(terms))

for x in (0.5, 2.0, 5.0):
    print(f"x = {x}: series J0 = {J_series(0, x):.10f}, scipy jv = {jv(0, x):.10f}, Y0 = {yv(0, x): .6f}")
x = 0.5: series J0 = 0.9384698072, scipy jv = 0.9384698072, Y0 = -0.444519
x = 2.0: series J0 = 0.2238907791, scipy jv = 0.2238907791, Y0 =  0.510376
x = 5.0: series J0 = -0.1775967713, scipy jv = -0.1775967713, Y0 = -0.308518

Zeros of Bessel functions and drums

J0J_0 oscillates like a decaying cosine, with zeros j0,1≈2.405j_{0,1} \approx 2.405, j0,2≈5.520,…j_{0,2} \approx 5.520, \dots. A circular drum of radius aa clamped at the edge vibrates in radially symmetric modes J0(j0,kr/a)J_0(j_{0,k}r/a), with frequencies proportional to j0,kj_{0,k}. Since these are not integer multiples of each other, a drum does not sound a clean musical note the way a string does.

python · try it yourself
from scipy.special import jn_zeros

z = jn_zeros(0, 4)
print("zeros of J0:", z.round(4))
print("frequency ratios to the lowest mode:", (z / z[0]).round(3))
zeros of J0: [ 2.4048  5.5201  8.6537 11.7915]
frequency ratios to the lowest mode: [1.    2.295 3.598 4.903]

Legendre's equation

(1−x2)y′′−2xy′+n(n+1) y=0.(1 - x^2)y'' - 2xy' + n(n + 1)\,y = 0.

x=0x = 0 is an ordinary point, and the recurrence ak+2=(k−n)(k+n+1)(k+2)(k+1)aka_{k+2} = \frac{(k - n)(k + n + 1)}{(k + 2)(k + 1)}a_k terminates when nn is a non-negative integer: the Legendre polynomials P0=1P_0 = 1, P1=xP_1 = x, P2=12(3x2−1)P_2 = \frac{1}{2}(3x^2 - 1), P3=12(5x3−3x)P_3 = \frac{1}{2}(5x^3 - 3x), … (scaled so Pn(1)=1P_n(1) = 1). The singular points x=±1x = \pm 1 correspond to the poles of a sphere when x=cos⁡θx = \cos\theta, and only the polynomial solutions stay finite there.

They are orthogonal on [−1,1][-1, 1]: ∫−11PmPn dx=0\int_{-1}^1 P_mP_n\,dx = 0 for m≠nm \ne n, and 22n+1\frac{2}{2n + 1} for m=nm = n.

python · try it yourself
import numpy as np
import sympy as sp
from scipy.integrate import quad
from scipy.special import eval_legendre

x = sp.symbols("x")
print([sp.expand(sp.legendre(n, x)) for n in range(4)])
for m, n in ((2, 3), (3, 3), (4, 4)):
    val, _ = quad(lambda t: eval_legendre(m, t) * eval_legendre(n, t), -1, 1)
    print(f"integral P{m} P{n} = {val:.6f}   (2/(2n+1) = {2 / (2 * n + 1):.6f})")
[1, x, 3*x**2/2 - 1/2, 5*x**3/2 - 3*x/2]
integral P2 P3 = -0.000000   (2/(2n+1) = 0.285714)
integral P3 P3 = 0.285714   (2/(2n+1) = 0.285714)
integral P4 P4 = 0.222222   (2/(2n+1) = 0.222222)

In software

  • scipy.special provides jv, yv, jn_zeros, eval_legendre, lpmv (associated Legendre functions) and spherical harmonics sph_harm.
  • Spherical harmonics, built from Legendre functions, are used in computer graphics for real-time lighting ("spherical harmonic lighting" of irradiance in game engines) and in geodesy for Earth's gravity models.
  • Gauss-Legendre quadrature uses the zeros of PnP_n as integration nodes (Gaussian Quadrature).

Exercises

Exercise 1: Check a Legendre polynomial

Verify that P2=12(3x2−1)P_2 = \frac{1}{2}(3x^2 - 1) solves Legendre's equation with n=2n = 2.

Answer

It does: all terms cancel.

Solution

P2′=3xP_2' = 3x, P2′′=3P_2'' = 3. Then (1−x2)3−2x(3x)+6⋅12(3x2−1)=3−3x2−6x2+9x2−3=0(1 - x^2)3 - 2x(3x) + 6 \cdot \frac{1}{2}(3x^2 - 1) = 3 - 3x^2 - 6x^2 + 9x^2 - 3 = 0.

Exercise 2: Small-xx behaviour

Use the series to approximate J1(x)J_1(x) for small xx.

Answer

J1(x)≈x2−x316J_1(x) \approx \frac{x}{2} - \frac{x^3}{16}.

Solution

k=0k = 0: 10! Γ(2)x2=x2\frac{1}{0!\,\Gamma(2)}\frac{x}{2} = \frac{x}{2}. k=1k = 1: −11! Γ(3)(x2)3=−x316-\frac{1}{1!\,\Gamma(3)}\left(\frac{x}{2}\right)^3 = -\frac{x^3}{16}.

Exercise 3: Drum frequencies (code)

A drum's lowest radially symmetric mode is at 100 Hz. Where are the next two such modes?

Answer

About 229.5 Hz and 359.8 Hz.

Solution

Frequencies scale with the zeros of J0J_0:

python · try it yourself
from scipy.special import jn_zeros
z = jn_zeros(0, 3)
print((100 * z / z[0]).round(1))
[100.  229.5 359.8]

Test yourself

Which Bessel function stays finite at x=0x = 0?

  1. JnJ_n
  2. YnY_n
  3. both
  4. neither

Legendre's equation has polynomial solutions when…

  1. nn is a non-negative integer
  2. nn is negative
  3. always
  4. never

Why does a drum not sound like a single musical note with harmonics?

  1. Its mode frequencies follow the zeros of J0J_0, which are not integer multiples
  2. It has only one mode
  3. Bessel functions are periodic
  4. Drums have no modes