![]() |
Home | Libraries | People | FAQ | More |
#include <boost/math/special_functions/struve.hpp> namespace boost { namespace math { // Struve function H_nu(x): template <class T1, class T2> calculated-result-type struve_h(T1 nu, T2 x, calculated-result-type* derivative = nullptr); template <class T1, class T2, class Policy> calculated-result-type struve_h(T1 nu, T2 x, calculated-result-type* derivative, const Policy&); template <class T1, class T2, class Policy> calculated-result-type struve_h(T1 nu, T2 x, const Policy&); // Modified Struve function L_nu(x): template <class T1, class T2> calculated-result-type struve_l(T1 nu, T2 x, calculated-result-type* derivative = nullptr); template <class T1, class T2, class Policy> calculated-result-type struve_l(T1 nu, T2 x, calculated-result-type* derivative, const Policy&); template <class T1, class T2, class Policy> calculated-result-type struve_l(T1 nu, T2 x, const Policy&); }} // namespaces
The Struve function and the modified Struve function of real order ν are
Hν(x) = ∑k=0∞ (-1)k (x/2)2k+ν+1 / (Γ(k + 3/2) Γ(k + ν + 3/2)),
Lν(x) = ∑k=0∞ (x/2)2k+ν+1 / (Γ(k + 3/2) Γ(k + ν + 3/2))
(DLMF 11.2.1, 11.2.2). They
are particular solutions of the inhomogeneous Bessel and modified Bessel equations,
and appear in acoustics (the radiation impedance of a piston), hydrodynamics
and optics. When derivative
is not null it receives the derivative with respect to x,
computed alongside the value.
double d; double h = boost::math::struve_h(0.0, 1.0, &d); // H_0(1) = 0.568656627048287951..., H_0'(1) = 0.438162436165636944... double l = boost::math::struve_l(1.0, 2.5); // L_1(2.5) = 1.988030772235941619...
Both functions are defined for x ≥ 0 and every real order. For negative x they are real only for integer orders, where Hn(-x) = (-1)n+1 Hn(x) and likewise for L; for other orders a negative x is a domain_error, as are infinite or NaN arguments.
At x = 0 both functions are 0 for ν > -1 and 2/π for ν = -1. For ν < -1 they are infinite (the first term of the series is (x/2)ν+1 / (Γ(3/2) Γ(ν + 3/2))), and the result is an overflow_error with the sign of 1/Γ(ν + 3/2), except at ν = -3/2, -5/2, ..., where H-n-1/2 = (-1)n Jn+1/2 and L-n-1/2 = In+1/2 vanish. The derivative at 0 is 2/π for ν = 0, 0 for ν > 0, ν = -1 and ν = -3/2, -5/2, ..., and infinite otherwise.
Lν(x) grows like ex, and overflows double near x = 710; that is reported as an overflow_error. Hν(x) behaves like (x/2)ν-1 / (√π Γ(ν + 1/2)) at large x and stays representable in double over the tested range. The implementation has been tested for -20 ≤ ν ≤ 100 and 0 ≤ x ≤ 104; it works for larger |ν| as well, more slowly (negative orders and the series cost about one term per unit of |ν|) and, above ν = 170 in double, where Γ overflows and the prefactor is formed from lgamma, less accurately.
The errors below are measured in double against the power series evaluated in MPFR at the exact double arguments, with enough precision to absorb its cancellation (about 1.44 x extra bits), and checked at a second precision; reporting/accuracy/struve_reference.jl generates the test values the same way in Julia. Errors are given in units of the conditioning envelope max(1/2, |x f'(x)f(x)|/2) ulps, the error committed by rounding /x alone, and in ulps. Grids are uniform in ν and logarithmic in x.
|
Function |
Region |
worst error / envelope |
worst error, ulps |
points outside the envelope |
|---|---|---|---|---|
|
H |
5 ≤ ν ≤ 100, 0.01 ≤ x ≤ 300 |
2.1 |
19 (where the condition number is 23) |
0.2% |
|
H |
-20 ≤ ν ≤ 100, 100 ≤ x ≤ 104 |
1.2 |
2 |
0.3% |
|
H |
-20 ≤ ν ≤ 100, 0.01 ≤ x ≤ 0.5 |
4.0 |
2 |
2% |
|
H |
-2 ≤ ν ≤ 12, 0.5 ≤ x ≤ 60 |
17 |
9 |
15% |
|
H |
-20 ≤ ν ≤ -1, 0.3 ≤ x ≤ 200 |
10 |
5 |
10% |
|
L |
-20 ≤ ν ≤ 100, 0.01 ≤ x ≤ 700 |
3.5 |
2 |
1% |
The "outside" points are almost all where the condition number is below 1 and the envelope is half an ulp, which only a correctly rounded function would meet; the errors there are a few ulps. The larger errors of H for small orders and moderate x (the fourth and fifth rows) come from cyl_neumann: where Hν = Kν + Yν and |Y| is comparable to |H|, the error of H is that of Yν, which is up to about 13 ulps for negative non-integer orders and 7 ulps for Y0 and Y1; Kν itself is accurate to an ulp or two.
Near ν = 1/2 the Struve function has near-double zeros: H1/2(x) = √(2/(πx)) (1 - cos x) touches 0 at x = 2πk. At ν = 1/2 exactly the closed form is used, with 1 - cos x = 2 sin2(x/2), and is accurate everywhere. For orders within a few hundredths of 1/2, K and Y cancel near those minima while the condition number there is small; the error reaches about 150 ulps (9 times the envelope) at ν = 0.504, x = 19.
The derivatives are generally accurate to a few ulps where they are well conditioned.
With cpp_bin_float_50 the errors
are within a few tens of ε times the condition number; float is computed in double
and rounded.
The methods, in the order they are tried:
The prefactors (x/2)ν+c / Γ(ν + d) are formed from tgamma1pm1 and the exact factors ν + d + i in double-word arithmetic, with the rounding errors of ν + c and ν + d carried to first order.
In double on an Apple M-series core (reporting/performance/struve_performance.cpp), the power series and the large-x expansions take about 0.1 μs, the Neumann series about 1 μs and the integral about 3 μs, against 16 ns for cyl_neumann; the derivative costs little more than the value.