Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Mathieu, parabolic cylinder and spheroidal wave functions

ProblemEvaluate the functions that separate the wave and heat equations in elliptic, parabolic and spheroidal coordinates: Mathieu functions and their characteristic values, parabolic cylinder functions, and spheroidal wave functions
Devised byÉmile Mathieu (1868), vibrations of an elliptic membrane; Heinrich Weber (1869), parabolic cylinder functions; Josef Meixner and Carson Flammer (1950s), spheroidal wave functions; Shanjie Zhang and Jianming Jin (1996), the algorithms in SciPy
AccuracyCharacteristic values to ; Mathieu and spheroidal functions to ; to against 50-digit references, where SciPy’s errs by up to ; spheroidal radial functions of the second kind satisfy their Wronskian to or better, where SciPy’s fail it by up to
CostOne tridiagonal eigenproblem of size about per characteristic value, then a series of that length
Read firstBessel functions, Hypergeometric functions
APImathieu (mathieu_a, mathieu_b, mathieu_cem, mathieu_sem, mathieu_modcem1, mathieu_modcem2, mathieu_modsem1, mathieu_modsem2); parabolic_cylinder (pbdv, pbvv, pbwa); spheroidal (pro_cv, obl_cv, pro_ang1, obl_ang1, pro_rad1, obl_rad1, pro_rad2, obl_rad2)

Overview

Separating the Helmholtz equation in Cartesian, cylindrical and spherical coordinates gives trigonometric, Bessel and Legendre functions. Three other coordinate systems give the functions of this entry.

  • Elliptic cylinder coordinates give Mathieu’s equation . Its periodic solutions , exist only for characteristic values , . Its modified form gives the radial functions , .

    The same equation governs a pendulum with a vibrating support, ions in a Paul trap, and waves in periodic media; the characteristic values chart its stable and unstable regions.

  • Parabolic cylinder coordinates give Weber’s equation , with solutions and , and , with solutions . These are also the quantum harmonic oscillator, barrier tunnelling, and uniform asymptotics near turning points.

  • Prolate and oblate spheroidal coordinates give . Its angular solutions exist for characteristic values , and come with radial solutions . They describe scattering by elongated bodies and antennas, and give the Slepian functions of time-frequency analysis.

Where it is used

These functions separate wave and heat equations in unusual coordinates.

  • Mathieu functions. Vibrations of an elliptical drum, waves in elliptical waveguides, and the stability of an ion in a quadrupole trap (the Paul trap used in mass spectrometers).
  • Parabolic cylinder functions. Quantum tunnelling through a barrier, the Landau-Zener transition and the inverted oscillator.
  • Spheroidal wave functions. Prolate spheroidal functions give the signals most concentrated in both time and frequency, used in the design of windows and in the study of band-limited signals.

History

Mathieu met his equation in 1868 while studying the vibrations of an elliptic drum. Weber met the parabolic cylinder functions a year later, and Niven the spheroidal ones in 1880. Their theory was systematised by McLachlan (1947) for Mathieu functions, and by Meixner and Schäfke (1954) and Flammer (1957) for spheroidal functions. Computing them well remained awkward until Zhang and Jin’s Computation of Special Functions (1996), whose Fortran routines SciPy wraps.

The idea

Characteristic values as eigenvalues

Substituting into Mathieu’s equation gives a three-term recurrence. The families , , , each give one, for example Truncated, each recurrence is a tridiagonal matrix whose eigenvalues are the characteristic values in increasing order, and whose eigenvectors are the Fourier coefficients. The off-diagonal products are positive, so the matrix is similar to a symmetric one: the implicit QL method gives the eigenvalues and inverse iteration the eigenvectors.

The spheroidal functions work the same way. Expanding in associated Legendre functions gives Flammer’s three-term recurrence for the . Its eigenvalues are ; in the oblate case is replaced by .

Figure 6.20. Mathieu characteristic values against q. At q = 0 they are m²; as q grows, aₘ and bₘ₊₁ merge in pairs, and between the curves lie the bands of the Mathieu equation's unstable solutions.

Radial functions as Bessel series

The modified Mathieu functions are series of products of Bessel functions (DLMF 28.24). With and , with or for the first and second kinds. The pivot is chosen at the largest coefficient to avoid cancellation. The spheroidal radial functions of the first kind are likewise series of spherical Bessel functions with weights .

Parabolic cylinder functions without cancellation

Near the origin, and are combinations of an even and an odd series. For large , however, decays like while both series grow like , so their combination loses about digits: seven at , which is where Zhang and Jin switch to asymptotics. The library avoids the cancellation:

  • for : from the integral (DLMF 12.5.1) evaluated by the exp-sinh quadrature rule, and for by the recurrence upward from two such values.
  • : grows, so its series are safe; an asymptotic series takes over for .
  • Negative : connection formulas written with , so that integer orders are not special cases.

Radial functions of the second kind

The radial functions of the first kind are regular at (prolate) or (oblate), and are series of spherical Bessel functions . The second solution of the radial equation , with for prolate and for oblate, is with as (Flammer’s normalisation, as ). The outgoing combination behaves like the spherical Hankel function , and has an asymptotic series in . Substituting into the equation, multiplied by to make its coefficients polynomial, gives a five-term recurrence: started from . The series diverges, but its terms first shrink: the library sums it up to the smallest term, which needs somewhat above and is of the order of relative to the sum: about at . The imaginary part of the sum and of its derivative are and at that point, and the equation is integrated inward from there to the wanted (Dormand and Prince’s 5(4) pair, relative tolerance ). Inward, the second-kind solution is the dominant one: it grows like (like for ) as the singular point is approached, so an error in the regular component cannot spoil it. The real part of the same sum is the first-kind function, since has no component at infinity; this is how the construction was checked against the series of the first kind.

The two solutions satisfy a Wronskian identity, , which makes an independent test of any implementation.

Normalisations

SciPy’s conventions are followed throughout:

  • Mathieu: with and (DLMF 28.2.30). Angles are in degrees, but derivatives are taken with respect to radians.
  • Spheroidal angular functions: Flammer’s normalisation, , or when is odd. The associated Legendre functions are taken without the Condon-Shortley phase.

Implementation

/// The tridiagonal matrix of the Fourier-coefficient recurrence of a family (`q ≥ 0`):
/// diagonal `h_k²` (with `±q` in the first entry of the odd families) and off-diagonals `q`,
/// except the coupling of `A₀` and `A₂`, which is `2q` below the diagonal.
fn matrix(f: Family, q: f64, size: usize) -> (Vec<f64>, Vec<f64>, Vec<f64>) {
    let mut d: Vec<f64> = (0..size).map(|k| f.harmonic(k).powi(2)).collect();
    let sup = vec![q; size - 1];
    let mut sub = vec![q; size - 1];
    match f {
        Family::CeEven => sub[0] = 2.0 * q,
        Family::CeOdd => d[0] += q,
        Family::SeOdd => d[0] -= q,
        Family::SeEven => {}
    }
    (d, sup, sub)
}
/// The modified (radial) Mathieu functions of the first (`kind = 1`) and second (`kind = 2`)
/// kind by Bessel-function product series (DLMF 28.24): with `u₁ = √q e^{−z}`, `u₂ = √q e^{z}`,
/// e.g. `Mc_{2n}^{(j)}(z) = Σ_k (−1)^{k+n} A_{2k}/A_{2s} [J_{k−s}(u₁) C_{k+s}(u₂) + J_{k+s}(u₁) C_{k−s}(u₂)] / ε_s`,
/// where `s` is the index of the largest coefficient (for accuracy), `ε₀ = 2`, `ε_s = 1`
/// otherwise, and `C = J` or `Y`. Returns the value and the derivative in `z`; `q > 0`.
fn modified(m: usize, q: f64, z: f64, kind: usize, sine: bool) -> (f64, f64) {
    if q <= 0.0 || (sine && m == 0) {
        return (f64::NAN, f64::NAN);
    }
    let direct = modified_direct(m, q, z, kind, sine);
    if direct.0.is_finite() && direct.1.is_finite() { direct } else { modified_scaled(m, q, z, kind, sine) }
}

/// The product series with the Bessel functions evaluated directly: fast, and exact to rounding
/// until the high-order functions overflow or underflow (a product of an underflowed `J` and an
/// overflowed `Y` is NaN), which happens beyond about `q = 2·10⁴`.
fn modified_direct(m: usize, q: f64, z: f64, kind: usize, sine: bool) -> (f64, f64) {
    let f = Family::of(m, sine);
    let (_, c) = solve(f, m, q);
    let h = q.sqrt();
    let (u1, u2) = (h * (-z).exp(), h * z.exp());
    let s = (0..c.len()).max_by(|&a, &b| c[a].abs().total_cmp(&c[b].abs())).unwrap();
    // Offsets: Mc_{2n}: (k−s, k+s); Mc_{2n+1}, Ms_{2n+1}: (k−s, k+s+1); Ms_{2n+2}: (k−s, k+s+2).
    let off = match f {
        Family::CeEven => 0,
        Family::CeOdd | Family::SeOdd => 1,
        Family::SeEven => 2,
    };
    let minus = sine;
    let n = f.index(m) as i64;
    let (mut val, mut der) = (0.0, 0.0);
    for (k, ck) in c.iter().enumerate() {
        let k = k as i64;
        let sk = s as i64;
        let sign = if (k + n) % 2 == 0 { 1.0 } else { -1.0 };
        let w = sign * ck / c[s];
        let (j1a, dj1a) = bessel(1, k - sk, u1);
        let (c2a, dc2a) = bessel(kind, k + sk + off, u2);
        let (j1b, dj1b) = bessel(1, k + sk + off, u1);
        let (c2b, dc2b) = bessel(kind, k - sk, u2);
        let pm = if minus { -1.0 } else { 1.0 };
        val += w * (j1a * c2a + pm * j1b * c2b);
        // d/dz: J(u₁)' brings −u₁, C(u₂)' brings +u₂.
        der += w * ((-u1 * dj1a) * c2a + j1a * (u2 * dc2a) + pm * ((-u1 * dj1b) * c2b + j1b * (u2 * dc2b)));
    }
    let eps = if f == Family::CeEven && s == 0 { 2.0 } else { 1.0 };
    (val / eps, der / eps)
}
/// `D_v(x)` for `x ≥ 0`: for `v < 0` from `D_v(x) = e^{−x²/4}/Γ(−v) ∫₀^∞ t^{−v−1} e^{−t²/2 − xt} dt`
/// (DLMF 12.5.1), and for `v ≥ 0` by the recurrence `D_{w+1} = x D_w − w D_{w−1}` from two
/// such values. Unlike the power series, neither step cancels for large `x`.
fn dv_positive(v: f64, x: f64) -> f64 {
    let e = (-0.25 * x * x).exp();
    if v == 0.0 {
        return e;
    }
    let by_integral = |w: f64| e * rgamma(-w) * laplace_gauss(-w, x);
    if v < 0.0 {
        return by_integral(v);
    }
    let n = v.floor() as i64 + 1;
    let w0 = v - n as f64; // in [−1, 0)
    let (mut dm, mut d) = (by_integral(w0 - 1.0), by_integral(w0));
    let mut w = w0;
    for _ in 0..n {
        let next = x * d - w * dm;
        dm = d;
        d = next;
        w += 1.0;
    }
    d
}
/// The characteristic value `λ_mn(c)` and the expansion coefficients `d_r` (`r ≡ n − m`
/// mod 2, step 2) from Flammer's three-term recurrence
/// `α_r d_{r+2} + (β_r − λ) d_r + γ_r d_{r−2} = 0`, with `κ = c²` (prolate) or `−c²` (oblate):
/// `α_r = (2m+r+2)(2m+r+1) κ / ((2m+2r+3)(2m+2r+5))`,
/// `β_r = (m+r)(m+r+1) + (2(m+r)(m+r+1) − 2m² − 1) κ / ((2m+2r−1)(2m+2r+3))`,
/// `γ_r = r(r−1) κ / ((2m+2r−3)(2m+2r−1))`. The coefficients are normalised so that
/// `Σ (2m+r)!/r! d_r = (n+m)!/(n−m)!`: the angular function tends to `P_n^m` as `c → 0`.
fn solve(m: usize, n: usize, c: f64, oblate: bool) -> (f64, Vec<f64>, usize) {
    let kappa = if oblate { -c * c } else { c * c };
    let p = (n - m) % 2;
    let size = (n - m) / 2 + 30 + (1.5 * c.abs()) as usize;
    let r_of = |j: usize| p + 2 * j;
    let (mf, kf) = (m as f64, kappa);
    let d: Vec<f64> = (0..size)
        .map(|j| {
            let r = r_of(j) as f64;
            (mf + r) * (mf + r + 1.0) + (2.0 * (mf + r) * (mf + r + 1.0) - 2.0 * mf * mf - 1.0) * kf / ((2.0 * mf + 2.0 * r - 1.0) * (2.0 * mf + 2.0 * r + 3.0))
        })
        .collect();
    let sup: Vec<f64> = (0..size - 1)
        .map(|j| {
            let r = r_of(j) as f64;
            (2.0 * mf + r + 2.0) * (2.0 * mf + r + 1.0) * kf / ((2.0 * mf + 2.0 * r + 3.0) * (2.0 * mf + 2.0 * r + 5.0))
        })
        .collect();
    let sub: Vec<f64> = (1..size)
        .map(|j| {
            let r = r_of(j) as f64;
            r * (r - 1.0) * kf / ((2.0 * mf + 2.0 * r - 3.0) * (2.0 * mf + 2.0 * r - 1.0))
        })
        .collect();
    let lam = if c == 0.0 { (n * (n + 1)) as f64 } else { eigenvalues(&d, &sup, &sub)[(n - m) / 2] };
    let mut v = if c == 0.0 {
        let mut e = vec![0.0; size];
        e[(n - m) / 2] = 1.0;
        e
    } else {
        eigenvector(&d, &sup, &sub, lam)
    };
    let s: f64 = v.iter().enumerate().map(|(j, dj)| ratio(m, r_of(j)) * dj).sum();
    let target = ratio(m, n - m);
    v.iter_mut().for_each(|x| *x *= target / s);
    (lam, v, p)
}
/// The coefficients `a_k` of the large-`ξ` expansion `R^{(3)} = R^{(1)} + i R^{(2)} ~ e^{icξ} Σ a_k ξ^{−k−1}`
/// of the outgoing radial solution, from the five-term recurrence that the radial equation
/// `(ξ² − s) R'' + 2ξ R' − (λ − c²ξ² + s m²/(ξ² − s)) R = 0` gives (`s = 1` prolate, `−1` oblate):
/// `2ic j a_j = A₁ a_{j−1} + A₂ a_{j−2} + A₃ a_{j−3} + A₄ a_{j−4} + A₅ a_{j−5}`, started from
/// `a₀ = (−i)^{n+1}/c` so that `R^{(3)} ~ h_n^{(1)}(cξ)`, i.e. `R^{(1)} ~ j_n(cξ)` and
/// `R^{(2)} ~ y_n(cξ)` (Flammer's normalisation). The series diverges, but its smallest term is of
/// the order of `e^{−2cξ}`. Returns `R^{(3)}` and its derivative at `ξ`, or `None` if the terms
/// do not get small enough (`cξ` too small for this `λ`).
fn outgoing(m: usize, n: usize, c: f64, lambda: f64, xi: f64, s: f64) -> Option<(Complex<f64>, Complex<f64>)> {
    let i = Complex::new(0.0, 1.0);
    let a0 = Complex::new(0.0, -1.0).powi(n as i32 + 1) / c;
    let mut a: Vec<Complex<f64>> = vec![a0];
    let (mut f, mut fp) = (a0 / xi, -a0 / (xi * xi));
    let mut previous = f64::INFINITY;
    let at = |a: &[Complex<f64>], j: i64| if j >= 0 { a[j as usize] } else { Complex::new(0.0, 0.0) };
    for j in 1..400i64 {
        let jf = j as f64;
        let a1 = (s * c * c - lambda) + jf * (jf - 1.0);
        let a2 = i * (2.0 * c * s * (2.0 * jf - 3.0));
        let a3 = s * (lambda - s * c * c - (m * m) as f64 - 2.0 * (jf - 2.0) * (jf - 2.0));
        let a4 = i * (-2.0 * c * (jf - 3.0));
        let a5 = (jf - 4.0) * (jf - 3.0);
        let aj = (a1 * at(&a, j - 1) + a2 * at(&a, j - 2) + a3 * at(&a, j - 3) + a4 * at(&a, j - 4) + a5 * at(&a, j - 5)) / (i * (2.0 * c * jf));
        a.push(aj);
        let term = aj / xi.powi(j as i32 + 1);
        let size = term.norm();
        if j > 8 && size > previous {
            // The terms have started to grow: stop at the smallest, if it is small enough.
            return if previous < 1e-16 * f.norm() { Some(finish(c, xi, f, fp)) } else { None };
        }
        previous = size;
        f += term;
        fp += -(jf + 1.0) * aj / xi.powi(j as i32 + 2);
        if size < 1e-17 * f.norm() {
            return Some(finish(c, xi, f, fp));
        }
    }
    None
}

fn finish(c: f64, xi: f64, f: Complex<f64>, fp: Complex<f64>) -> (Complex<f64>, Complex<f64>) {
    let e = Complex::new(0.0, c * xi).exp();
    (e * f, e * (fp + Complex::new(0.0, c) * f))
}

/// The radial function of the second kind and its derivative by integrating the radial equation
/// inward from where the large-`ξ` expansion of `R^{(3)}` is accurate (`Im R^{(3)} = R^{(2)}`: the
/// real part is `R^{(1)}`, whose asymptotic form is `j_n`, so no phase shift arises). Toward
/// `ξ = 1` the second-kind solution is the dominant one, so the integration is stable. The
/// integrator is Dormand and Prince's embedded 5(4) pair with step control.
fn radial_second(m: usize, n: usize, c: f64, xi: f64, oblate: bool) -> (f64, f64) {
    if n < m || (!oblate && xi <= 1.0) || (oblate && xi < 0.0) || c <= 0.0 || !xi.is_finite() {
        return (f64::NAN, f64::NAN);
    }
    let s = if oblate { -1.0 } else { 1.0 };
    let lambda = if oblate { obl_cv(m, n, c) } else { pro_cv(m, n, c) };
    // The starting point: far enough that the expansion converges (2cξ above λ, and at least 30/c).
    let mut x0 = xi.max(30.0 / c).max(lambda.abs() / c);
    let start = loop {
        match outgoing(m, n, c, lambda, x0, s) {
            Some(v) => break v,
            None if x0 < 1e7 => x0 *= 2.0,
            None => return (f64::NAN, f64::NAN),
        }
    };
    let (mut y, mut yp) = (start.0.im, start.1.im);
    if x0 == xi {
        return (y, yp);
    }
    let mm = (m * m) as f64;
    let rhs = |x: f64, y: f64, yp: f64| -> f64 { ((lambda - c * c * x * x + s * mm / (x * x - s)) * y - 2.0 * x * yp) / (x * x - s) };
    // Dormand-Prince 5(4), integrating from x0 down to xi (a negative step).
    let (mut x, mut h) = (x0, -(0.05 / c).min(0.1 * (x0 - xi)));
    let tol = 1e-13;
    let mut guard = 0u64;
    while x > xi {
        guard += 1;
        if guard > 5_000_000 {
            return (f64::NAN, f64::NAN);
        }
        if x + h < xi {
            h = xi - x;
        }
        let f1 = (yp, rhs(x, y, yp));
        let st = |k: &[(f64, f64)], w: &[f64]| (y + h * k.iter().zip(w).map(|(a, b)| a.0 * b).sum::<f64>(), yp + h * k.iter().zip(w).map(|(a, b)| a.1 * b).sum::<f64>());
        let s2 = st(&[f1], &[1.0 / 5.0]);
        let f2 = (s2.1, rhs(x + h / 5.0, s2.0, s2.1));
        let s3 = st(&[f1, f2], &[3.0 / 40.0, 9.0 / 40.0]);
        let f3 = (s3.1, rhs(x + 3.0 * h / 10.0, s3.0, s3.1));
        let s4 = st(&[f1, f2, f3], &[44.0 / 45.0, -56.0 / 15.0, 32.0 / 9.0]);
        let f4 = (s4.1, rhs(x + 4.0 * h / 5.0, s4.0, s4.1));
        let s5 = st(&[f1, f2, f3, f4], &[19372.0 / 6561.0, -25360.0 / 2187.0, 64448.0 / 6561.0, -212.0 / 729.0]);
        let f5 = (s5.1, rhs(x + 8.0 * h / 9.0, s5.0, s5.1));
        let s6 = st(&[f1, f2, f3, f4, f5], &[9017.0 / 3168.0, -355.0 / 33.0, 46732.0 / 5247.0, 49.0 / 176.0, -5103.0 / 18656.0]);
        let f6 = (s6.1, rhs(x + h, s6.0, s6.1));
        let new = st(&[f1, f3, f4, f5, f6], &[35.0 / 384.0, 500.0 / 1113.0, 125.0 / 192.0, -2187.0 / 6784.0, 11.0 / 84.0]);
        let f7 = (new.1, rhs(x + h, new.0, new.1));
        // The difference between the fifth- and fourth-order results.
        let e = [71.0 / 57600.0, -71.0 / 16695.0, 71.0 / 1920.0, -17253.0 / 339200.0, 22.0 / 525.0, -1.0 / 40.0];
        let ks = [f1, f3, f4, f5, f6, f7];
        let err_y = h * ks.iter().zip(&e).map(|(k, w)| k.0 * w).sum::<f64>();
        let err_yp = h * ks.iter().zip(&e).map(|(k, w)| k.1 * w).sum::<f64>();
        let scale_y = tol * (y.abs().max(new.0.abs()) + 1e-300);
        let scale_yp = tol * (yp.abs().max(new.1.abs()) + 1e-300);
        let err = (err_y.abs() / scale_y).max(err_yp.abs() / scale_yp);
        if err <= 1.0 {
            x += h;
            y = new.0;
            yp = new.1;
        }
        let factor = if err == 0.0 { 5.0 } else { (0.9 * err.powf(-0.2)).clamp(0.2, 5.0) };
        h *= factor;
        // Near the singular point at ξ = 1 the steps shrink with the distance to it.
        if !oblate {
            h = -h.abs().min(0.5 * (x - 1.0).max(1e-12));
        }
        if x <= xi {
            break;
        }
    }
    (y, yp)
}
  • Characteristic values come from the symmetric form of each matrix. The coefficient vectors come from inverse iteration on the original, non-symmetric matrix.
  • pro_rad2 and obl_rad2 start the integration at (doubled until the series converges), so their cost grows with and, for very small , with . Measured in release mode at (prolate) and (oblate): 0.5 ms for at , 8 ms at , 30 ms at and 64 ms at ; with takes 2.7 ms. That is fast enough that no second algorithm was added. The oblate functions are finite at , and so is the library’s obl_rad1, which there returns the limit of the series (only the term contributes to the value and only to the derivative).

In practice

The references are from SciPy 1.17.1, written by book/generator/data/make_wave220_refs.py. For the parabolic cylinder functions, both the library and SciPy are compared with 50-digit values from mpmath:

Table 6.15. Mathieu, parabolic cylinder and spheroidal wave functions against SciPy (and mpmath).

FunctionCasesLargest relative difference (value; derivative)
mathieu_a, mathieu_b569e-16; 7e-16
mathieu_cem3362e-12; 3e-11
mathieu_sem2884e-12; 1e-11
mathieu_modcem1964e-13; 2e-12
mathieu_modcem2965e-14; 8e-14
mathieu_modsem1803e-13; 2e-12
mathieu_modsem2806e-14; 3e-14
pbdv against mpmath (50 digits)81library 2e-14; SciPy 1e-1
pbvv against mpmath (50 digits)79library 6e-11; SciPy 2e-10
pbwa against mpmath (50 digits)42library 2e-9; SciPy 4e-10
pro_cv, obl_cv323e-15; 4e-15
pro_ang11601e-13; 2e-14
obl_ang11601e-12; 3e-13
pro_rad11282e-12; 4e-12
obl_rad11282e-13; 3e-13
  • Mathieu and spheroidal functions agree with SciPy to about or better: the same eigenproblems and series, solved independently.
  • is more accurate than SciPy’s. Where SciPy’s power series loses digits to cancellation, with errors up to in these cases, the integral representation keeps them.
  • is computed by power series in both libraries. Near the turning point both lose a few digits to cancellation.

Large . The modified Mathieu functions of the first and second kind have the Wronskian for every order, argument and , and the same for . An error in either function’s coefficients, or a leak of the first kind into the second, changes it, and there is no other reference at these (SciPy’s routines are not reliable there). The worst deviation over , and the cosine and sine families:

Table 6.16. Wronskian of the modified Mathieu functions at large q.

qLargest relative deviation of the Wronskian from 2/πCases returning NaN
103e-150 of 20
1002e-150 of 20
10002e-150 of 20
50008e-150 of 20
100009e-150 of 20
200008e-140 of 20

Spheroidal radial functions of the second kind. Each case is checked against SciPy’s and by the Wronskian identity, whose relative residual measures the error of and its derivative with the library’s :

Table 6.17. `pro_rad2` and `obl_rad2` against SciPy, and the Wronskian residual of each.

CaseLibrary R⁽²⁾SciPy R⁽²⁾Relative differenceWronskian residual, libraryWronskian residual, SciPy
prolate, m = 0, n = 0, c = 1, ξ = 1.5-0.2629632165-0.26296321656e-112e-136e-10
prolate, m = 0, n = 3, c = 2, ξ = 1.2-2.1318744358-2.13187443581e-132e-132e-15
prolate, m = 1, n = 2, c = 0.5, ξ = 3-1.4622835690-1.46228356902e-132e-131e-15
prolate, m = 2, n = 4, c = 3.5, ξ = 1.05-5.1184975065-5.11611200715e-41e-132e-5
prolate, m = 3, n = 3, c = 8, ξ = 1.30.1296150140-21.44521011872e21e-122e2
prolate, m = 0, n = 1, c = 15, ξ = 1.010.16021610060.16021610066e-119e-138e-11
prolate, m = 4, n = 7, c = 2.5, ξ = 1.5-22.3324767022-22.33149621614e-53e-139e-6
prolate, m = 2, n = 2, c = 20, ξ = 2-0.0248890325-0.02488903254e-113e-112e-11
oblate, m = 0, n = 0, c = 1, ξ = 0.5-0.6890905746-0.00000000001e02e-131e0
oblate, m = 0, n = 3, c = 2, ξ = 1.2-0.5833496267-0.00000000001e02e-131e0
oblate, m = 1, n = 2, c = 0.5, ξ = 3-1.2489707526-1.24897075262e-132e-134e-16
oblate, m = 2, n = 4, c = 3.5, ξ = 0.05-3.2991041210-1.74861327275e-11e-135e-1
oblate, m = 3, n = 3, c = 8, ξ = 0.30.14562104430.08211133964e-12e-134e-1
oblate, m = 0, n = 1, c = 15, ξ = 0.01-0.0684243196-0.00000000001e02e-121e0

Where SciPy’s values are accurate the two agree to or better, and the library’s Wronskian residual is to throughout. SciPy’s own residuals show where its routine fails: up to for the larger orders near , an of the wrong sign and size for , , , and denormal numbers in place of the oblate values in half of the oblate cases (including , , ). The comparison with SciPy is therefore a check only where SciPy is right.

Strengths

  • One method, a tridiagonal eigenproblem plus a series, for all the characteristic values and periodic functions, with no tabulated starting guesses.
  • accurate for large arguments, where SciPy’s is not.
  • SciPy’s conventions throughout, including degrees for the Mathieu argument.

Weaknesses

  • Large or need large matrices and long series. The modified Mathieu functions stay accurate to (by the Wronskian test below) up to . Beyond that, and for large earlier, the product series needs Bessel functions of order up to about at the small argument , which underflow, while those at the large argument overflow, so the products are . Since 2.40 the functions fall back, where the direct evaluation is not finite, to a scaled one that holds every Bessel function as a sign and a logarithm (Miller’s backward recurrence for , the forward recurrence for , both rescaled), and the products are formed as . It agrees with the direct one to where both are finite, and keeps the Wronskian at to at and (the tests’ limit; the cost is the eigenproblem and the tables, which grow with ).
  • pbwa goes beyond SciPy’s range (inside it the series is unchanged). Outside it, W(a, x) is carried from by Taylor steps of length at most , which is stable in the oscillatory region and for the growing solution (Wronskian residual for up to 50 and from to ; values equal to mpmath’s to at and ). For , the solution decays through the barrier and an integration from 0 would lose of its accuracy, so there it is computed from the integral representation of the complex parabolic cylinder function (DLMF 12.14.4, 12.5.1), with an exp-sinh rule: for to (the stepped value was wrong in the third digit), and to the right sign and size where the stepped value was . Values this small are determined by cancellation in a real part and carry a few digits less than the oscillatory ones.
  • No Mathieu functions of complex argument.

Exercises

  1. Show that for the matrix of the family is diagonal with entries , so that .
  2. Why are ?
  3. Derive the recurrence from the integral representation.
  4. Why does the series for lose about digits?
  5. Derive the Wronskian from the radial equation, and find the constant from the large- behaviour.
  6. Why is the inward integration of the second-kind function stable, and the outward integration of the first-kind function not?
Hints and answers
  1. Every off-diagonal entry is a multiple of .
  2. Replacing by changes the sign of and turns into .
  3. Integrate from 0 to ∞.
  4. The two series grow like and the result decays like , a ratio of .
  5. Write the equation as . For two solutions, , so is constant. With and , , the leading part of is , so the constant is .
  6. Toward the singular point the second solution grows (like ) while the first stays bounded, so an error in the mix of the two is dwarfed by the growth of the one wanted. Outward, the first-kind solution is the smaller of the two near the singular point, and an error of rounding size in the second-kind component grows relative to it until it dominates.

Further reading

  • S. Zhang and J. Jin, Computation of Special Functions, Wiley, 1996, chapters 13–15.
  • C. Flammer, Spheroidal Wave Functions, Stanford University Press, 1957.
  • N. W. McLachlan, Theory and Application of Mathieu Functions, Oxford, 1947.
  • NIST Digital Library of Mathematical Functions, chapters 12, 28 and 30 (dlmf.nist.gov).
  • J. Meixner and F. W. Schäfke, Mathieusche Funktionen und Sphäroidfunktionen, Springer, 1954.