A12 · Lesson 45 · Lab: special functions in code
Bessel zeros, Legendre expansions, Green's function integrals and induced charge
Lessons 38 to 44 leaned on tables: Bessel zeros like 2.4048, Legendre polynomials, Green's functions. In this lab you'll compute those numbers yourself. You'll sum Bessel's series and find its zeros, which give drum overtones and waveguide cutoffs. You'll build Legendre polynomials by recursion and expand a function in them. Then you'll solve a loaded string by integrating its Green's function, and check that a point charge above a grounded plane induces exactly its own charge, with the opposite sign.
- The curves are and , computed from their power series. Their zeros are where drums, fibers and waveguides have their modes.
- The power series converges for every x, but for large x its terms grow huge before they cancel. With 60 terms in double precision the series is good to about at x = 20 and only at x = 30.
- The readout gives the drum's first overtone ratio, , from the zeros of these two curves.
Predict
A drumhead's fundamental is 100 Hz. Where is its next mode, (1, 1)?
159 Hz. Mode frequencies go as the Bessel zeros, and the (1, 1) mode uses the first zero of , 3.8317, against 's 2.4048: a ratio of 1.593. The next, (2, 1), is at 214 Hz and (0, 2) at 230 Hz. None of these is a whole multiple of 100 Hz.
Name it
Series, recursions and their limits
- Bessel functions from : fine for moderate x. For large x the terms reach about before canceling, so rounding errors of times that remain. Libraries switch to asymptotic forms there.
- Legendre polynomials from Bonnet's recursion : stable and exact on .
- Zeros by bisection inside brackets where the function changes sign.
Expansions
On the Legendre polynomials are orthogonal with , so with . The same pattern, with different weights, holds for Bessel series on a disk.
Green's functions as code
A Green's function turns a boundary-value problem into an integral: . Numerically that's one quadrature per point, and it works for any load f, measured data included.
Worked example
Find the first three zeros of from its series.
Show the solution
- Bracket the zeros. Tabulating shows sign changes in (2, 3), (5, 6) and (8, 9).
- Bisect. Bisection in each, with the 60-term series, gives 2.404826, 5.520078 and 8.653728, matching the tables to all six figures.
- The gaps. They are 3.115 and 3.134, approaching π: for large x, a slowly fading cosine.
- Check the approximation. It gives the third zero as , already within 0.2%.
Answer the first three zeros of are 2.404826, 5.520078 and 8.653728.
Worked example
Expand on in Legendre polynomials.
Show the solution
- Only even terms. f is even, so only even n appear, and
- The n = 0 term. With : .
- The n = 2 term. With : so .
- The n = 4 term. With :
- The expansion.
- Check at the kink. At x = 0 that gives The error at the kink shrinks slowly as terms are added, while away from it the series converges quickly.
Answer .
Check
A circular drumhead of radius 0.1 m has wave speed 50 m/s. What is its fundamental?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
Check
Expand on in Legendre polynomials.
(a)
What is ?
(b)
What is ?
Check
Write J(n, x) summing 60 terms of the Bessel series and bisect(f, a, b). Set z0 to the first three zeros of (brackets (2, 3), (5, 6), (8, 9)) and ratio to the first zero of (bracket (3, 4.5)) over the first of .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write legendre(n, x) using Bonnet's recursion (x may be a NumPy array). On 200 001 points of , set a to the coefficients to of , and norm3 to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A string on (0, 1) satisfies with fixed ends. Using for and for , set u03 to (trapezoid rule, 100 001 points) and exact to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A charge q = 1 sits at height h = 1 above a grounded plane, inducing . Set total to with , using the trapezoid rule on np.concatenate([[0], np.logspace(-6, 4, 200001)]), and tail to the charge beyond R, .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does the power series for lose accuracy at large x even though it converges for every x?
For large x the individual terms grow enormous before the factorials win: at x = 30 the largest is about . The terms alternate in sign and cancel down to a result smaller than 1. Each term carries a relative rounding error near , so the sum inherits an absolute error of about times the largest term, around , and no number of extra terms fixes that. The series is exact in exact arithmetic; the trouble is cancellation in floating point. Libraries therefore switch to asymptotic expansions or recurrences for large x.
Practice
Keep practicing
4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.