Bessel and Airy functions
| Problem | Evaluate the Bessel functions , and modified Bessel functions , of real order, the spherical Bessel functions , , and the Airy functions , |
| Devised by | Daniel Bernoulli (1732) and Leonhard Euler (1736); Friedrich Wilhelm Bessel (1824); Carl Neumann (1867) and Heinrich Weber (1873), the second kind; George Biddell Airy (1838); evaluation by Steed’s method: A. R. Barnett and colleagues (1974), with Nico Temme’s series (1976) |
| Accuracy | About relative away from zeros; near a zero of an oscillating function the absolute error, not the relative error, is small |
| Cost | Continued fractions and a recurrence of steps, or a series for small |
| Read first | The gamma function and related functions |
| API | bessel_jy, bessel_ik, bessel_fractional and the single-function forms, bessel_j_integer and its relatives, bessel_spherical, bessel_spherical_y, airy_ai, airy_bi |
Overview
Bessel functions are the solutions of Bessel’s equation
which appears whenever the Laplace, wave, heat or Schrödinger equation is separated in cylindrical coordinates. They describe the vibration modes of a drum, the electromagnetic modes of a circular waveguide or optical fibre, the diffraction pattern of a circular aperture (the Airy disc), the temperature in a cylinder, and frequency modulation. The modified functions solve the equation with replaced by , and grow or decay instead of oscillating; the spherical functions arise in spherical coordinates, for scattering by spheres and the quantum states of atoms. The Airy functions, solutions of , describe the transition from oscillation to decay at a turning point: the light near a caustic, the rainbow, and the quantum particle in a uniform field.
Where it is used
Bessel functions are the natural functions of anything round or cylindrical.
- Waves in cylinders. Modes of circular waveguides and optical fibres, vibrations of a drum, and sound in a pipe.
- Heat and diffusion. Temperature in a cylinder or disc, and diffusion in pipes.
- Signal processing. The Kaiser window uses a modified Bessel function; FM spectra have Bessel-function sidebands.
- Electromagnetics. Fields of a wire, antenna patterns of circular apertures, and the skin effect in conductors.
- Airy functions. Quantum tunnelling, optics near a caustic and the rainbow.
History
Daniel Bernoulli met the function now called in 1732, describing the oscillations of a hanging chain, and Euler found in 1736 studying vibrating membranes. Friedrich Wilhelm Bessel, analysing the perturbations of planetary orbits, made the first systematic study in 1824, from the integral , which also solves Kepler’s equation. Carl Neumann and Heinrich Weber introduced the functions of the second kind. George Biddell Airy, the Astronomer Royal, introduced his integral in 1838 to explain the supernumerary bows of the rainbow. G. N. Watson’s Treatise on the Theory of Bessel Functions (1922) remains the classic reference.
Computing Bessel functions reliably took decades of work. J. C. P. Miller (1952) showed that their three-term recurrence must be run downward for when . A. R. Barnett, D. H. Feng, J. W. Steed and L. J. B. Goldfarb (1974) devised the continued-fraction method used here, and Nico Temme (1976) gave series that make it work for small arguments.
The idea
Bessel functions of real order
Bessel’s equation is a second-order differential equation, so it has two independent solutions for each order . The standard pair is , the Bessel function of the first kind, which is finite at the origin, and , the second kind, which is infinite there. Every solution is a combination of the two.
What they look like. For large the term in the equation becomes negligible, and the solutions behave like sines and cosines whose amplitude decays slowly:
and are thus related as cosine and sine are. For small they differ completely: tends to zero (or to 1 for ), while diverges.
Figure 6.6. Bessel functions J and Y.
The recurrence, and its danger. Functions of neighbouring orders are linked. Both and (and the modified functions below, with a change of sign) satisfy
Given two neighbouring orders, this yields the next, which looks like an easy way to compute many orders from two. But the recurrence is a trap. Because both and satisfy it, any rounding error introduces a small multiple of the other solution into the computed sequence. For orders , grows rapidly with while decays rapidly. So when recurring upward for , the unwanted trace of grows at each step and eventually swamps the answer. Recurring upward for is safe, because the contamination by shrinks. In the downward direction the roles are reversed: it is safe for . The solution that decays in a given direction, here for increasing order, is called the minimal solution, and a recurrence must never be run in the direction in which the wanted solution is minimal.
Steed’s method. The algorithm uses the recurrence only in its safe directions, and gets the values it needs to start from two continued fractions.
- A continued fraction (CF1) gives the ratio . It comes from the recurrence itself, run to infinity, and determines only up to an unknown scale factor.
- Downward recurrence, the safe direction for , carries that unscaled solution from order to a small order . This gives the ratio of to .
- A second, complex continued fraction (CF2) gives . Together with the Wronskian identity , a known relation between the two solutions and their derivatives, this is enough to fix the actual values of , and their derivatives.
- is carried upward, its safe direction, to order , and follows from the ratio found in step 2.
CF2 converges only for . For smaller , Temme’s series for and replace it. Negative orders use the reflection formulas and similarly for .
Modified Bessel functions
Replacing by in Bessel’s equation changes the sign of the term. The solutions no
longer oscillate; like and compared with and , they grow or decay
exponentially. The standard pair is , which grows like
, and , which decays like . They are computed by the
same strategy (bessik), with real continued fractions in place of the complex one.
Bessel functions of integer order
For integer orders the same routines are used; integer orders add the symmetries and , so integer-order functions are defined for negative arguments too.
Spherical Bessel functions
The spherical Bessel functions are Bessel functions of half-integer order,
and are elementary: , . The library computes them from the real-order routines, using the closed form for .
Airy functions
and solve : oscillating for , decaying and growing super-exponentially for . They are Bessel functions of order in the variable : for example for . The library uses this for and the Maclaurin series near 0.
Figure 6.7. Modified Bessel functions and Airy functions.
Accuracy
Table 6.4. Accuracy of the Bessel and Airy functions.
| function | test points | median relative error | largest relative error | at arguments |
|---|---|---|---|---|
bessel_jy | 90 | 2e-15 | 7e-12 | (-1.3, 60) |
bessel_jy | 90 | 1e-15 | 4e-12 | (0, 1000) |
bessel_ik | 80 | 3e-16 | 9e-14 | (50.5, 3.3) |
bessel_ik | 80 | 2e-16 | 3e-15 | (50.5, 0.1) |
bessel_j_integer | 25 | 3e-16 | 4e-14 | (0, 50) |
bessel_y_integer | 25 | 5e-16 | 1e-13 | (20, 50) |
bessel_i_integer | 25 | 2e-16 | 9e-15 | (20, 10) |
bessel_k_integer | 25 | 1e-16 | 1e-15 | (20, 0.1) |
bessel_spherical | 25 | 4e-16 | 1e-13 | (2, 50) |
bessel_spherical_y | 25 | 2e-16 | 6e-13 | (5, 50) |
airy_ai | 25 | 6e-16 | 1e-11 | (-30.5) |
airy_bi | 26 | 4e-16 | 2e-13 | (100) |
The largest errors, near , are at large arguments of oscillating functions (, ). There the function value depends on the phase , and a relative change in shifts the phase by : no method working in double precision can do much better.
Algorithm
bessel_jy(ν, x) returns , and their derivatives for .
- Negative order. If , compute the functions for by the steps below and combine them with the reflection formulas.
- Split the order. Write with an integer and .
- CF1. Evaluate the first continued fraction by the modified Lentz algorithm to get the ratio . Give an arbitrary small trial value, and the value the ratio implies.
- Downward recurrence. Apply the recurrence times to carry the trial values down to order . This gives and up to the same unknown factor.
- Normalise at order . For , evaluate CF2, a complex continued fraction, and combine its real and imaginary parts with the ratio from step 4 and the Wronskian to obtain the true , and their derivatives. For , sum Temme’s series for and instead, and obtain from the Wronskian.
- Rescale . The ratio of the true to its trial value is the unknown factor; multiply the trial and of step 3 by it.
- Upward recurrence. Apply the recurrence times to carry up to .
The cost is proportional to plus the number of terms of CF1, which grows with .
bessel_ik(ν, x) follows the same seven steps for and , with the recurrence
for modified functions and real continued fractions.
Spherical Bessel functions call bessel_jy with order and multiply by
. Airy functions use the Maclaurin series for and the Bessel
functions of order and in otherwise.
Implementation
The Airy function through the order-⅓ Bessel functions:
/// The Airy function Ai(x).
pub fn airy_ai(x: f64) -> f64 {
if x.is_nan() {
return f64::NAN;
}
if x.abs() <= SERIES_LIMIT {
let (f, g) = series_fg(x);
return AI0 * f - AIP0 * g;
}
if x > 0.0 {
let z = 2.0 / 3.0 * x * x.sqrt();
if z > 745.0 {
return 0.0;
}
let k = bessel_ik(1.0 / 3.0, z).1;
(x / 3.0).sqrt() / PI * k
} else {
let ax = -x;
let z = 2.0 / 3.0 * ax * ax.sqrt();
let (j, y) = bessel_jy(1.0 / 3.0, z);
0.5 * ax.sqrt() * (j - y / 3f64.sqrt())
}
}
- The Steed and Temme routines follow Numerical Recipes’
bessjyandbessik; they are long, and are inbessel_functions_fractional.rs. bessel_jyandbessel_ikreturn both functions of a pair, sharing the work; the single-function forms call them.- , , are handled explicitly; negative is allowed only where the function is real.
In practice
//! Bessel and Airy functions.
//!
//! Run with `cargo run -p lib_jsl_special_functions --example special_bessel`.
use lib_jsl_special_functions::{airy_ai, bessel_fractional, bessel_ik, bessel_j_integer, bessel_jy, bessel_spherical};
use lib_jsl_root_finding::{bracket_roots_scan, brent_method};
fn main() {
// The first zeros of J₀ give the vibration frequencies of a circular drum.
let zeros: Vec<f64> = bracket_roots_scan(|x| bessel_j_integer(0, x), 0.5, 15.0, 300)
.into_iter()
.map(|(a, b)| brent_method(|x| bessel_j_integer(0, x), a, b, 1e-14).unwrap())
.collect();
println!("zeros of J₀: {zeros:.10?}");
let (j, y) = bessel_jy(2.5, 7.0);
println!("J_2.5(7) = {j:.15}, Y_2.5(7) = {y:.15}");
// Half-integer orders are elementary: J_½(x) = √(2/(πx)) sin x, and j₀(x) = sin x / x.
let x: f64 = 3.0;
println!("J_½(3) = {:.15} = {:.15}", bessel_fractional(0.5, x), (2.0 / (std::f64::consts::PI * x)).sqrt() * x.sin());
println!("j₀(3) = {:.15} = {:.15}", bessel_spherical(0, x), x.sin() / x);
let (i, k) = bessel_ik(1.0, 2.0);
println!("I₁(2) = {i:.15}, K₁(2) = {k:.15}");
println!("Ai(−2.338107410459767) = {:.2e} (the first zero)", airy_ai(-2.338107410459767));
}
Strengths
- Real orders of either sign, both kinds together, near machine precision.
- Integer, spherical and Airy functions built on the same core.
Weaknesses
- Real arguments only (no Hankel functions or complex arguments).
- The cost grows with (the continued fractions need about terms), so very large arguments are slow; asymptotic expansions would be faster there.
Exercises
- Verify that satisfies Bessel’s equation with .
- Run the recurrence for upward from and to and compare with
bessel_j_integer. Explain the growth of the error, and fix it by running downward from (Miller’s algorithm). - The modes of a circular drum of radius 1 vibrate at frequencies proportional to the zeros of . Find the first three zeros of , and and order the modes by frequency.
- Show that the Airy function solves by differentiating .
- The intensity of the Airy disc is . Find the radius of the first dark ring.
Hints and answers
- With , reduces, after substituting , to , which solves.
- The upward recurrence is unstable for because decays like while the other solution, , grows: rounding errors excite the growing solution and the error grows by a factor of about each step. Miller’s algorithm runs the recurrence downward from a large (where the solution decays in the direction of iteration), from arbitrary starting values, and normalises with .
- Zeros of : ; of : ; of : . In order of frequency: .
- Differentiate twice with the Bessel recurrences for and collect terms; the result reduces to because satisfies the modified Bessel equation of order in the variable .
- The first dark ring is the first zero of : .
Further reading
- G. N. Watson, A Treatise on the Theory of Bessel Functions, 2nd ed., Cambridge University Press, 1944.
- A. R. Barnett, D. H. Feng, J. W. Steed and L. J. B. Goldfarb, “Coulomb wave functions for all real η and ρ”, Computer Physics Communications 8 (1974) 377–395.
- N. M. Temme, “On the numerical evaluation of the ordinary Bessel function of the second kind”, Journal of Computational Physics 21 (1976) 343–350.
- NIST Digital Library of Mathematical Functions, chapters 9 and 10, https://dlmf.nist.gov/10.
- W. H. Press et al., Numerical Recipes, 3rd ed., Cambridge University Press, 2007, §6.5–6.7.