Class BesselFunction
Bessel Function Implementations
Utility case for computing various Bessel functions that are not included in the Java API.
Implementations for integer-order cylindrical Bessel functions of the first and second kind (i.e., Jn(x) and Yn(x), n = 1,2,3,... )were taken from www.koders.com and the copyright notice is included in the Java source file. The implementation is based upon that presented in Numerical Recipes by W.H. Press, et. al.
Spherical Bessel functions jn(x) can be
represented as cylindrical Bessel functions with half-integer order.
Specifically, we have
jn(x) =
(π/2x)1/2Jn+½(x).
However, since half-order cylindrical Bessel functions are not included in
this class (they are more difficult to implement), an implementation based
upon the above formula is not feasible. Instead, spherical Bessel functions
jn(x) for n = 0, 1, 2, 3, 4 are
implemented using their trigonometric representations.
NOTES: (CKA)
· There exists a recurrence relationship between Bessel functions of
different orders. For example, if Bn(x) is any
cylindrical Bessel function of order n, we have the following:
Bn+1(x) =
(2n/x)Bn(x) -
Bn-1(x).
However, this formula is numerically unstable for Bessel functions of the
first kind Jn(x). Thus, it cannot be used to
compute the higher order Jn(x) using recursion
over lower orders.
· We can apply the above recurrence relation to spherical Bessel
functions by expressing them in terms of cylindrical Bessel functions.
Letting
bn(x) represent any spherical Bessel function we
have
bn+1(x) =
[(2n+1)/x]bn(x) -
bn-1(x).
Again, this formula is numerically unstable for the Bessel functions of the
first kind jn(x). However, it can be used to
determine the representation of each Bessel function in terms of
trigonometric functions.
References
[1] www.koders.com[2]Numerical Recipes, The Art of Scientific Computing, Third Edition, W.H. Press, S.A. Teukolsky, W.T. Vetterling, B.P. Flannery (Cambridge University Press, Cambridge, 2007).
- Author:
- Christopher K. Allen
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
smallest tolerance value - not used at the momentstatic final double
the value PI/2static final double
Conditional value where polynomial expansions are employedstatic final int
number of Units in the Last Place (ULPs) used for bracketing approximately equal values -
Method Summary
Modifier and TypeMethodDescriptionstatic double
j0
(double x) Zero-Order Spherical Bessel Function of the First Kindstatic double
J0
(double x) Compute the zeroth order Bessel function of the first kind, J0(x).static double
j1
(double x) First-Order Spherical Bessel Function of the First Kindstatic double
J1
(double x) Compute the first-order Bessel function of the first kind, J1(x).static double
j2
(double x) Second-Order Spherical Bessel Function of the First Kindstatic double
j3
(double x) Third-Order Spherical Bessel Function of the First Kindstatic double
j4
(double x) Fourth-Order Spherical Bessel Function of the First Kindstatic double
Jn
(int n, double x) Arbitrary Order Bessel Function of First Kindstatic double
sinc
(double x) Implementation of the sinc Functionstatic double
y0
(double x) Compute the zeroth order Bessel function of the second kind, Y0(x).static double
y1
(double x) Compute the first-order Bessel function of the second kind, Y1(x).static double
yN
(int n, double x) Arbitrary Order Bessel Function of Second Kind
-
Field Details
-
ULPS_BRACKET
public static final int ULPS_BRACKETnumber of Units in the Last Place (ULPs) used for bracketing approximately equal values- See Also:
-
PI_BY_2
public static final double PI_BY_2the value PI/2- See Also:
-
EPS
public static final double EPSsmallest tolerance value - not used at the moment- See Also:
-
SMALL_ARG
public static final double SMALL_ARGConditional value where polynomial expansions are employed- See Also:
-
-
Method Details
-
J0
public static double J0(double x) Compute the zeroth order Bessel function of the first kind, J0(x).- Parameters:
x
- a double value- Returns:
- the Bessel function of order zero in the argument, J0(x).
-
J1
public static double J1(double x) Compute the first-order Bessel function of the first kind, J1(x).- Parameters:
x
- a double value- Returns:
- the Bessel function of order 1 of the argument, J1(x).
-
Jn
public static double Jn(int n, double x) Arbitrary Order Bessel Function of First Kind
Computes integer order Bessel function of the first kind, Jn(x).
This implementation relies upon evaluation of the zero and first order Bessel functions J0(x) and J1(x)..
- Parameters:
n
- integer orderx
- a double value- Returns:
- the Bessel function of order n of the argument, Jn(x).
- See Also:
-
y0
public static double y0(double x) Compute the zeroth order Bessel function of the second kind, Y0(x).
This implementation relies upon evaluation of the zero order Bessel function Y0(x).
- Parameters:
x
- a double value- Returns:
- the Bessel function of the second kind, of order 0 of the argument, Y0(x).
- See Also:
-
y1
public static double y1(double x) Compute the first-order Bessel function of the second kind, Y1(x).
This implementation relies upon evaluation of the first order Bessel function Y1(x).
- Parameters:
x
- a double value- Returns:
- the Bessel function of the second kind, of order 1 of the argument, Y1(x).
- See Also:
-
yN
public static double yN(int n, double x) Arbitrary Order Bessel Function of Second Kind
Computes integer order Bessel function of the second kind, Yn(x).
This implementation relies upon evaluation of the zero and first order Bessel functions Y0(x) and Y1(x).
- Parameters:
n
- integer orderx
- a double value- Returns:
- the Bessel function of the second kind, of order n of the argument, Yn(x).
-
sinc
public static double sinc(double x) Implementation of the sinc Function
The sinc function arises frequency in engineering applications, especially communications and signal processing. It is defined as follows:
sinc(x) ≡ sin(x)/x.
The function is not singular at x = 0, which may easily be verified with L'hopital's rule.To avoid numerical instability, for small values of x we Taylor expand sinc(x) to sixth order about x = 0.
sinc(x) ≈ 1 - x2/6 + x4/120 - x6/5040 + O(x8).
otherwise we return sin(x)/x.NOTE: (CKA)
· The sinc function is the zeroth order spherical Bessel function j0.- Parameters:
x
- any real number- Returns:
- sinc(x) ≡ sin(x)/x
-
j0
public static double j0(double x) Zero-Order Spherical Bessel Function of the First Kind
This function is simply an alias for the
sinc
function, which is the first spherical Bessel function, j0(x).- Parameters:
x
- any real number (double value)- Returns:
- spherical Bessel function of the first kind of order 0, j0(x)
- See Also:
-
j1
public static double j1(double x) First-Order Spherical Bessel Function of the First Kind
Direct computation of the first-order spherical Bessel function of the first kind, j1(x) in terms of trigonometric functions.
To avoid numerical instability, for small values of x we Taylor expand j1(x) to seventh order about x = 0.
j1(x) ≈ x/3 - x3/30 + x5/840 - x7/45360 + O(x9).
otherwise we return
j1(x) = sin(x)/x2 - cos(x)/x.- Parameters:
x
- any real number (double value)- Returns:
- first-order spherical Bessel function of the first kind, j1(x)
-
j2
public static double j2(double x) Second-Order Spherical Bessel Function of the First Kind
Direct computation of the second-order spherical Bessel function of the first kind, j2(x) in terms of trigonometric functions.
To avoid numerical instability, for small values of x we Taylor expand j2(x) to eighth order about x = 0.
j2(x) ≈ x2/15 - x4/210 + x6/7560 - x8/498960 + O(x10).
otherwise we return
j2(x) = (3/x - 1)sin(x)/x - 3cos(x)/x2.- Parameters:
x
- any real number (double value)- Returns:
- second-order spherical Bessel function of the first kind, j2(x)
-
j3
public static double j3(double x) Third-Order Spherical Bessel Function of the First Kind
Direct computation of the third-order spherical Bessel function of the first kind, j3(x) in terms of trigonometric functions.
To avoid numerical instability, for small values of x we Taylor expand j3(x) to seventh order about x = 0.
j3(x) ≈ x3/105 + x5/1890 - x7/83160 + O(x9).
otherwise we return
j3(x) = (15/x3 - 6/x)sin(x)/x - (1 - 15/x2)cos(x)/x.- Parameters:
x
- any real number (double value)- Returns:
- third-order spherical Bessel function of the first kind, j3(x)
-
j4
public static double j4(double x) Fourth-Order Spherical Bessel Function of the First Kind
Direct computation of the fourth-order spherical Bessel function of the first kind, j4(x) in terms of trigonometric functions.
To avoid numerical instability, for small values of x we Taylor expand j4(x) to eighth order about x = 0.
j2(x) ≈ x4/945 - x6/20790 + x8/1081080 + O(x10).
otherwise we return
j4(x) = (1 - 45/x2 + 105/x4)sin(x)/x + (10/x - 105/x3)cos(x)/x.- Parameters:
x
- any real number (double value)- Returns:
- fourth-order spherical Bessel function of the first kind, j4(x)
-