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

Faddeeva, Struve, Kelvin and Hankel functions

ProblemEvaluate the Faddeeva function and the Voigt line profile, the Struve functions and , the Kelvin functions , , , and their derivatives, the Hankel functions , , and the zeros of , and their derivatives
Devised byVera Faddeeva and Nikolai Terent’ev (1954, tables of ); Woldemar Voigt (1912); J. A. C. Weideman (1994, rational approximation of ); Hermann Struve (1882); William Thomson, Lord Kelvin (1889); Hermann Hankel (1869); James McMahon (1895, asymptotic zeros)
AccuracyAbout relative for (both parts, in the upper half plane) and the Kelvin functions; for the Struve functions; zeros to . Where SciPy is less accurate (Kelvin functions near , ), the library agrees with closed forms and power series
Cost: one rational function of degree 40, a continued fraction of depth 40 or a Taylor series of up to 60 terms; Kelvin: trapezoid sums of 40–200 complex exponentials; Struve: at most four series of up to a few hundred terms
Read firstIncomplete gamma and beta functions and the error function, Bessel and Airy functions
APIwofz, voigt_profile; struve_h, struve_l; kelvin (kelvin, ber, bei, ker, kei, berp, beip, kerp, keip); hankel (hankel1, hankel2, hankel1e, hankel2e); bessel_zeros (jn_zeros, jnp_zeros, yn_zeros, ynp_zeros)

Overview

These functions complete the library’s coverage of scipy.special for the Bessel family and the error function:

  • The Faddeeva function is the error function of a complex argument, scaled so that it neither overflows nor underflows. Its real part on a line parallel to the real axis is the Voigt profile, the convolution of a Gaussian and a Lorentzian. It is the shape of spectral lines broadened both by thermal motion (Doppler, Gaussian) and by collisions or the finite lifetime of the state (Lorentzian).
  • The Struve functions and are particular solutions of the Bessel equation with a power on the right-hand side. They appear in the radiation impedance of a piston in a baffle, in unsteady aerodynamics and in water waves.
  • The Kelvin functions are the Bessel functions and along the diagonal of the complex plane. They give the current in a wire carrying alternating current (the skin effect) and the deflection of plates on elastic foundations.
  • The Hankel functions are outgoing and incoming cylindrical waves.
  • The zeros of the Bessel functions give the resonant frequencies of drums and cylindrical cavities, and the nodes of Fourier-Bessel series.

Where it is used

A collection of functions for spectral lines, rotating fields and cylindrical problems.

  • Spectroscopy and astrophysics. The Voigt profile (Doppler plus pressure broadening of a spectral line) is the real part of the Faddeeva function.
  • Plasma physics. The plasma dispersion function for waves in a hot plasma.
  • Electrical engineering. Kelvin functions describe the skin effect (current in a round wire at high frequency) and the AC resistance of conductors.
  • Acoustics and hydrodynamics. Struve functions in the radiation of a piston in a baffle.

History

Woldemar Voigt (1912) introduced the convolution that bears his name to describe spectral lines. Vera Faddeeva and Nikolai Terent’ev (1954) tabulated for the Soviet nuclear programme, and Walter Gautschi (1970) gave the first reliable algorithm. J. A. C. Weideman (1994) found the rational approximation used here, and Steven G. Johnson’s Faddeeva package (2012), which SciPy uses, combined it with continued fractions and special cases near the real axis.

Hermann Struve (1882) introduced in a study of diffraction by a circular aperture. William Thomson (Lord Kelvin, 1889) defined and for the alternating-current resistance of conductors, and Alexander Russell (1909) added and . Hermann Hankel (1869) introduced the functions of the third kind, and James McMahon (1895) gave the asymptotic expansion of Bessel zeros.

The idea

The Faddeeva function

is entire, with and the reflection which takes the lower half plane to the upper, where . On the real axis with Dawson’s integral . In the upper half plane there are three regimes:

  • Near the real axis (, ) the real part, , is far smaller than . Any method accurate relative to loses its digits. The Taylor series in about the real axis keeps them: follow from by the recurrence , which comes from differentiating .
  • For , Weideman’s approximation Here is a polynomial of degree whose coefficients are a discrete Fourier transform of at . The map sends the upper half plane into the unit disc, where the polynomial converges geometrically.
  • For , Laplace’s continued fraction converges quickly; 40 levels suffice.

The Voigt profile with Gaussian standard deviation and Lorentzian half-width is

Struve functions

is defined by its power series which cancels badly once exceeds about 20. Three other representations cover the rest:

  • the Bessel series ;
  • the asymptotic expansion ;
  • for , the integral The integrand is smooth and positive, and the trapezoid rule after a double-exponential substitution gives it to full accuracy.

Each method returns an estimate of its own error, and the smallest wins. uses the same series with in place of and .

Kelvin functions

By definition and , with derivatives and . The integral representations have analytic integrands, so the trapezoid rule converges exponentially:

  • for , periodic with points;
  • for , on the half line with step 0.04, since the integrand is analytic in a strip of half-width .

Hankel functions and Bessel zeros

, computed from the library’s and ; the scaled forms multiply by . The zeros of , , and all lie above and are at least 2.5 apart. A scan in steps of ¼ from finds every sign change, and regula falsi with the Illinois modification refines each one to the last bit.

Implementation

/// The Faddeeva function `w(z) = e^{−z²} erfc(−iz)` (SciPy's `wofz`). On the real axis it is
/// `e^{−x²} + (2i/√π) D(x)` with Dawson's integral `D`; just above it (`0 < y ≤ ½`, `|x| < 9`) the
/// Taylor series in `y` about that, which keeps the small real part accurate; elsewhere in the
/// upper half plane, Weideman's rational approximation with 40 terms for `|z| < 6` and Laplace's
/// continued fraction beyond;
/// in the lower half plane, the reflection `w(z) = 2 e^{−z²} − w(−z)`. Relative accuracy about
/// 10⁻¹⁴ in the upper half plane, for the real and imaginary parts separately.
pub fn wofz(z: C) -> C {
    if z.re.is_nan() || z.im.is_nan() {
        return C::new(f64::NAN, f64::NAN);
    }
    if z.im == 0.0 {
        let x = z.re;
        return C::new((-x * x).exp(), 2.0 / PI.sqrt() * dawson_integral(x));
    }
    if z.im < 0.0 {
        return (-z * z).exp() * 2.0 - wofz(-z);
    }
    if z.im <= 0.5 && z.re.abs() < 9.0 {
        taylor_near_real_axis(z.re, z.im)
    } else if z.norm() >= 6.0 {
        continued_fraction(z)
    } else {
        weideman(z)
    }
}
/// The Struve function `H_ν(x)` (SciPy's `struve`), a particular solution of the inhomogeneous
/// Bessel equation `x²y'' + xy' + (x² − ν²)y = 4(x/2)^{ν+1}/(√π Γ(ν + ½))`. Of the defining
/// power series, the Bessel-function series, the large-`x` expansion about `Y_ν` and (for
/// `ν > −½`) the integral of `H_ν − Y_ν`, the one with the smallest error estimate is used.
/// Negative `x` only for integer orders.
pub fn struve_h(v: f64, x: f64) -> f64 {
    if v.is_nan() || x.is_nan() {
        return f64::NAN;
    }
    if x == 0.0 {
        return at_zero(v);
    }
    if x < 0.0 {
        return reflect(v, x, false);
    }
    struve_positive(v, x, false)
}
/// All four Kelvin functions and their derivatives at `x` (SciPy's `kelvin`): returns
/// `(ber + i bei, ker + i kei, ber' + i bei', ker' + i kei')`, from
/// `ber x + i bei x = I₀(x e^{iπ/4})` and `ker x + i kei x = K₀(x e^{iπ/4})`, with derivatives
/// `e^{iπ/4} I₁` and `−e^{iπ/4} K₁`. The `I` integrals use the periodic trapezoid rule, the `K`
/// integrals the trapezoid rule on the real half line; both converge exponentially. For `x < 0`
/// `ber` and `bei` are even and their derivatives odd, while `ker`, `kei` and theirs are `NaN`.
pub fn kelvin(x: f64) -> (C, C, C, C) {
    let nan = C::new(f64::NAN, f64::NAN);
    if x.is_nan() {
        return (nan, nan, nan, nan);
    }
    let r = rotation();
    let (i0, i1) = i01(r * x.abs());
    let (be, bep) = (i0, if x < 0.0 { -(r * i1) } else { r * i1 });
    if x < 0.0 {
        return (be, nan, bep, nan);
    }
    if x == 0.0 {
        return (be, C::new(f64::INFINITY, -FRAC_PI_4), bep, C::new(f64::NEG_INFINITY, 0.0));
    }
    let (k0, k1) = k01(r * x);
    (be, k0, bep, -(r * k1))
}
/// The first `nt` positive zeros `j_{n,k}` of `J_n` (SciPy's `jn_zeros`).
pub fn jn_zeros(n: u32, nt: usize) -> Vec<f64> {
    zeros(Kind::J, n, nt)
}

/// The first `nt` positive zeros `j'_{n,k}` of `J_n'` (SciPy's `jnp_zeros`); for `n = 0` the
/// zero at the origin is not counted, so these are the zeros of `J₁`.
pub fn jnp_zeros(n: u32, nt: usize) -> Vec<f64> {
    zeros(Kind::Jp, n, nt)
}

/// The first `nt` positive zeros `y_{n,k}` of `Y_n` (SciPy's `yn_zeros`).
pub fn yn_zeros(n: u32, nt: usize) -> Vec<f64> {
    zeros(Kind::Y, n, nt)
}

/// The first `nt` positive zeros `y'_{n,k}` of `Y_n'` (SciPy's `ynp_zeros`).
pub fn ynp_zeros(n: u32, nt: usize) -> Vec<f64> {
    zeros(Kind::Yp, n, nt)
}
  • Weideman’s 40 coefficients are computed once, on first use, by a direct discrete Fourier transform of 160 samples.
  • Struve functions at negative exist only for integer orders, where ; other orders return NaN, as in SciPy.
  • kelvin returns all four complex values at once; the eight real functions each compute only the half they need.

In practice

The references are from SciPy 1.17.1, written by book/generator/data/make_calc28_refs.py:

Table 6.14. Faddeeva, Voigt, Struve, Kelvin and Hankel functions and Bessel zeros against `scipy.special`.

FunctionValuesLargest relative difference from SciPyNotes
wofz, upper half plane409e-15Taylor series near the real axis, Weideman (|z| < 6), continued fraction beyond
wofz, real axis82e-16from Dawson’s integral
wofz, lower half plane162e-15reflection; relative to |w|, which grows like e^{y²}
voigt_profile407e-15including the pure Gaussian and Lorentzian
struve_h (H_ν)541e-13best of four methods by error estimate
struve_l (L_ν)544e-14at ν = −½ against √(2/(πx)) sinh x, from which SciPy differs by 8e-11
kelvin (all eight), x ∉ [8, 20)641e-13trapezoid rules for I₀, I₁, K₀, K₁ at x e^{iπ/4}
kelvin, x = 8 and 10165e-10SciPy’s expansion; the library agrees with the power series to 4e-16
hankel1, hankel2246e-14J ± iY
jn_zeros, jnp_zeros, yn_zeros, ynp_zeros1601e-15n = 0, 1, 5, 20; ten zeros each

The two rows where the library and SciPy differ by more than are SciPy’s. exactly, and SciPy’s value at is off by . SciPy’s Kelvin functions switch to an asymptotic expansion at , which is good to only about there. The library’s quadrature agrees with the power series, summed with compensation, to rounding.

Figure 6.18. Voigt profiles of unit area. The Gaussian () has the narrowest wings, the Lorentzian () the heaviest; mixtures keep a Gaussian core with Lorentzian wings.

Figure 6.19. The Kelvin functions and . and oscillate with growing amplitude ; and decay like .

Strengths

  • keeps full relative accuracy in both parts near the real axis, which is where the Voigt profile’s wings are evaluated.
  • Struve and Kelvin functions are more accurate than SciPy’s where SciPy switches methods.
  • The Kelvin quadrature has no regions to stitch together, and its accuracy follows from the analyticity of the integrands.

Weaknesses

  • The Kelvin functions cost 40–200 complex exponentials each, slower than SciPy’s series and expansions for large ; and they overflow beyond .
  • Struve functions of large order at small rely on the power series alone, and are limited by the accuracy of .
  • Only real arguments for the Struve, Kelvin and Hankel functions, and only integer orders for the zeros.

Exercises

  1. Show from the reflection formula that is real for real , and that .
  2. Show that the Voigt profile integrates to one, and that it tends to the Gaussian as and to the Lorentzian as .
  3. Verify from the power series.
  4. Why does the periodic trapezoid rule for need about points? (Hint: the error is the sum of the Fourier coefficients , .)
  5. Use McMahon’s expansion , , to estimate the tenth zero of , and compare with jn_zeros(0, 10).
Hints and answers
  1. With , and . On the real axis, .
  2. It is the density of the sum of a normal and an independent Cauchy variable; convolutions of densities are densities. The limits follow because one component tends to a point mass.
  3. With , ; the series is .
  4. The aliasing error is , and falls below only once exceeds by a margin.
  5. gives ; the zero is .

Further reading

  • J. A. C. Weideman, “Computation of the complex error function”, SIAM Journal on Numerical Analysis 31 (1994) 1497–1518.
  • W. Gautschi, “Efficient computation of the complex error function”, SIAM Journal on Numerical Analysis 7 (1970) 187–198.
  • S. G. Johnson, Faddeeva Package, MIT (2012), http://ab-initio.mit.edu/Faddeeva.
  • F. W. J. Olver et al., NIST Digital Library of Mathematical Functions, chapters 7 (error functions), 10 (Bessel and Kelvin functions) and 11 (Struve functions).
  • L. N. Trefethen and J. A. C. Weideman, “The exponentially convergent trapezoidal rule”, SIAM Review 56 (2014) 385–458.
  • G. N. Watson, A Treatise on the Theory of Bessel Functions, 2nd ed., Cambridge (1944).