| Home | Libraries | People | FAQ | More

### Spherical Bessel Functions of the First and Second Kinds

##### Synopsis

`#include <boost/math/special_functions/bessel.hpp>`

    template <class T1, class T2>
    calculated-result-type sph_bessel(unsigned v, T2 x);

    template <class T1, class T2, class Policy>
    calculated-result-type sph_bessel(unsigned v, T2 x, const Policy&);

    template <class T1, class T2>
    calculated-result-type sph_neumann(unsigned v, T2 x);

    template <class T1, class T2, class Policy>
    calculated-result-type sph_neumann(unsigned v, T2 x, const Policy&);

##### Description

The functions sph_bessel and sph_neumann return the result of the Spherical Bessel functions of the first and second kinds respectively:

sph_bessel(v, x) = jv(x)

sph_neumann(v, x) = yv(x) = nv(x)

where:

The return type of these functions is computed using the result type calculation rules for the single argument type T.

The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.

The functions return the result of domain_error whenever the result is undefined or complex: this occurs when `x < 0`.

The jv function is cyclic like Jv but differs in its behaviour at the origin:

Likewise yv is also cyclic for large x, but tends to -∞ for small x:

##### Testing

There are two sets of test values: spot values calculated using functions.wolfram.com, and a much larger set of tests computed using a simplified version of this implementation (with all the special case handling removed).

##### Accuracy

Table 6.48. Error rates for sph_bessel

| Microsoft Visual C++ version 12.0 Win32 double | GNU C++ version 5.1.0 linux long double | GNU C++ version 5.1.0 linux double | Sun compiler version 0x5130 Sun Solaris long double
--- | --- | --- | --- | ---
Bessel j: Random Data | Max = 245ε (Mean = 16.3ε) | Max = 243ε (Mean = 13.3ε) (<tr1/cmath>: Max = 1.91e+06ε (Mean = 1.09e+05ε)) | Max = 0.978ε (Mean = 0.0539ε) (GSL 1.16: Max = 1.79e+03ε (Mean = 107ε)) | Max = 243ε (Mean = 33.7ε)

Table 6.49. Error rates for sph_neumann

| Microsoft Visual C++ version 12.0 Win32 double | GNU C++ version 5.1.0 linux double | GNU C++ version 5.1.0 linux long double | Sun compiler version 0x5130 Sun Solaris long double
--- | --- | --- | --- | ---
y: Random Data | Max = 281ε (Mean = 31.1ε) | Max = 0.995ε (Mean = 0.0665ε) (GSL 1.16: Max = 8.5e+04ε (Mean = 5.33e+03ε)) | Max = 234ε (Mean = 19.5ε) (<tr1/cmath>: Max = 1.6e+06ε (Mean = 1.4e+05ε)) | Max = 234ε (Mean = 19.8ε)

##### Implementation

Other than error handling and a couple of special cases these functions are implemented directly in terms of their definitions:

The special cases occur for:

j0 = sinc_pi(x) = sin(x) / x

and for small x < 1, we can use the series:

which neatly avoids the problem of calculating 0/0 that can occur with the main definition as x → 0.