You are on page 1of 6

Computer Physics Communications 182 (2011) 663668

Contents lists available at ScienceDirect

Computer Physics Communications


www.elsevier.com/locate/cpc

On the computation of spherical Bessel functions of complex arguments


Liang-Wu Cai
Department of Mechanical and Nuclear Engineering, Kansas State University, Manhattan, KS 66506, United States

a r t i c l e

i n f o

a b s t r a c t

Article history:
Received 18 February 2010
Received in revised form 19 August 2010
Accepted 17 November 2010
Available online 26 November 2010
Keywords:
Spherical Bessel functions of rst kind
Spherical Bessel function of second kind
Spherical Hankel functions
Complex arguments
Recurrence

In this short paper, problems with existing algorithms for computing spherical Bessel functions of complex arguments are reported. As a remedy, a revised algorithm based on the recurrence is proposed. The
upper and lower limits for the starting order that can be used in the backward recurrence to reach a
desired accuracy are given. The proposed algorithm is stable and is capable of computing a wide range
of arguments approaching machine accuracy.
2010 Elsevier B.V. All rights reserved.

1. Introduction
Spherical Bessel functions of various kinds, including the Hankel functions, are often used in analyses for wave phenomena
in three-dimensional spaces, such as scattering, propagation, radiation problems of acoustic, electromagnetic and elastic waves.
Bessel functions of complex arguments are needed in such problems that involve attenuation or absorption of various forms.
The literature is rather extensive for the computation of cylindrical Bessel functions of complex arguments. But it is very limited
on their spherical counterparts. This is probably because the rst
few orders spherical Bessel functions have exact yet simple analytical expressions, which removes one of signicant challenges of
the task.
Despite being limited, the literature contains a complete set of
algorithms for the computation of spherical Bessel functions of
various kinds. Shafai, Towaij and Hamid [1] provided algorithms
(hereafter referred to as the STH algorithms) for spherical Bessel
functions of both the rst kind, jn ( z), and the second kind, yn ( z),
based on the recurrence relations of spherical Bessel functions

Forward: bn+1 ( z) =

2n + 1

b n ( z ) b n 1 ( z )
z
2n + 1
Backward: bn1 ( z) =
b n ( z ) b n +1 ( z )
z

0010-4655/$ see front matter


doi:10.1016/j.cpc.2010.11.019

2010 Elsevier B.V. All rights reserved.

2. The STH algorithms and their problems

(1)

For all the discussions that follow, denote the complex argument as z = re . For jn ( z), the STH j-algorithm uses the forward
recursion up to n  [r ], where the square brackets denote the
largest integer not exceeding the enclosed value. The seeds are
j 0 ( z) and j 1 ( z), computed from their respective analytical expressions

(2)

j 0 ( z) =

where bn ( z) is a spherical Bessel function of any kind. Hankel functions can be computed from their denitions using Bessel functions. Boston [2] proposed using a pair of real-valued alternative

E-mail address: cai@ksu.edu.

recurrences to circumvent the slow complex division in the original complex-valued recurrence.
However, serious aws in the STH algorithms may lead to erroneous results in some circumstances. The investigation to identify
the aws and their remedies prompted this short paper.
Another algorithm is briey discussed in Zhang and Jin [3]. The
idea is to use the backward recurrence to compute jn ( z); use analytical expressions to compute y 0 ( z) and y 1 ( z); then, the Wronskian relation between jn ( z) and yn ( z) is used as an alternative
form of recursion for computing yn ( z). This process works well
for jn ( z) and yn ( z); but when they are combined to obtain Hankel functions, signicant error would occur. The problem for the
case of cylindrical Bessel functions has been discussed in detail by
Heckmann and Dvorak [4].

sin z
z

j 1 ( z) =

sin z
z2

cos z
z

(3)

It then switches to the backward recursion, which starts from order M, with seeds j M ( z) = 0 and j M 1 ( z) set to a rough estimate.
The backward recursion stops at order n = [r ], where it overlaps
with the forward recursion. The results at the overlapped order are
used to determine the factor for normalizing the backward recursion series. Approximations for the starting order M and J M 1 ( z)

664

L.-W. Cai / Computer Physics Communications 182 (2011) 663668

Fig. 1. The FoM for computed jn (rei ) using the STH j-algorithm with given starting order M for magnitude of argument r ranges from 1 to 500 at three different phase
angles = 0 (left), 0.5 (center) and 1.5 (right). The color scale to the right represents the mapping between FoM values and colors in the images. The magenta area is not
computed, and the black area signies over- or under-ow. (For interpretation of the references to colors in this gure legend, the reader is referred to the web version of
this article.)

Fig. 2. Comparison of log10 | jn (100ei /6 )| computed by the STH j-algorithm with the correct result produced by the proposed algorithm.

for achieving 14 signicant gures for all orders up to the desired


maximum order N are given in [1]. It was noted that the value
of seed j M 1 ( z) is not an important factor for the accuracy of the
end result. As a common practice, j M 1 ( z) = 1 could be used [5].
For yn ( z), the STH y-algorithm directly uses the forward recursion, with seeds y 0 ( z) and y 1 ( z), computed from their respective
analytical expressions

y 0 ( z) =

cos z
z

y 1 ( z) =

cos z
z2

sin z
z

(4)

In implementing STH j-algorithm for this study, the forward


recursion is stopped at n = [r ] + 1. This way, two normalization
factors can be computed at the two overlapped orders n = [r ] and
[r ] + 1. The difference is indicative of the quality of the computation. For this purpose, the gure of merit of the computed jn ( z)
series is dened as



 | A1|

FoM = log10 
1
| A2|

(5)

where A 1 and A 2 are the normalization factors computed at orders


n = [r ] and [r ] + 1, respectively. The computed FoM is essentially
of the number of signicant gures.
In assessing the quality of the STH j-algorithm, the starting order M is selected a priori, ranging from 10 to 500. The recursions

are carried out, and the FoM is computed from the resulting series.
The resulting FoM for r ranging from 1 to 500 are shown in Fig. 1
for three different phase angles = 0, 0.5 and 1.5 radians. In this
set of gures, the magenta color signies M < r where the backward recursion is not used; and the black color signies under- or
over-ow. It can be seen that the STH j-algorithm generally works
for real arguments. But, with the increase of the phase angle, the
performance dramatically deteriorates. In the case of = 1.5, the
algorithm is unable to produce results of 10 or more signicant
gures for r > 10; and increasing M does not help.
To further illustrate the problem, log10 | jn (100ei /6 )| is computed for results using the STH j-algorithm and compared with
the correct result, produced by the proposed algorithm. The comparison is shown in Fig. 2. In the segment of forward recursion
(r  100), the STH curve deviates from the correct result after
n > 65. Consequently, the results from the backward recursion is
normalized by a wrong scaling factor, off by approximately an order of 1020 .
It becomes clear that the source of errors in the STH j-algorithm is the forward recursion. It is well known [5] that the recurrence should only be used in the direction of increasing amplitude.
As | jn ( z)| decreases monotonically with n, the forward recursion
should not be used. Unfortunately, STH y-algorithm is also awed
for the same reason. As n increases, | yn ( z)| decreases initially until

L.-W. Cai / Computer Physics Communications 182 (2011) 663668

665

Fig. 3. Starting order M for the backward recursion to achieve desired 13 signicant gures for spherical Bessel function of all orders up to 50.

n [r ], then it swings to monotonic increasing. A forward recursion will also cause signicant errors. A similar example was
discovered by de Toit [6] in the algorithm for cylindrical Bessel
function of the second kind deployed in an early version (v1.2) of
Wolframs Mathematica: Y n ( z), has the correct value in the order
of 108 , but the software gave a result of 1028 , off by an order of
1020 .
3. The proposed algorithm
To remedy the situation, the following general characteristics of
the spherical Bessel functions of complex arguments and integer
orders are observed rst:

The amplitude of jn (z) decreases monotonically as n increases,


with the exception in the region of n < | z| when z is real, in
which case | jn ( z)| is oscillatory.
The amplitude of yn (z) decreases initially as n increases, but
reverses to monotonic increasing after a turning point. When z
is real, the | yn ( z)| is oscillatory when n < | z|, and increases
monotonically when n > | z|.
The amplitude of the Hankel function of the rst kind,
(1)
|hn (z)|, increases monotonically as n increases when the im(1)
aginary part of z is positive. When z is real, |hn ( z)| is oscillatory when n  | z|, and increases monotonically when n > | z|.
It has a turning point similar to yn ( z) when the imaginary
part of the argument is negative.
The amplitude of the Hankel function of the second kind,
|h(2) (z)| behaves the same way as |h(1) (z)|, where the overbar denotes a complex conjugate.
Similar characteristics have been observed for cylindrical Bessel
functions. Specically, the turning point for Y n ( z) was noted by
de Toit [7], who also gave an equation for nding the turning point,
which is also applicable for yn ( z). The characteristics of cylindrical
Hankel functions with complex argument have been observed by
Mason [8] and Heckmann and Dvorak [4].
Based on these observed characteristics of spherical Bessel
functions, and the general principle that the recurrence shall only
be used in the direction of increasing amplitudes, the proposed algorithm for computing the entire set of spherical Bessel functions
of complex arguments and integer orders comprises the following:

The backward recursion is used exclusively for computing


jn ( z). The starting order M will be determined empirically
later, and with seeds j M ( z) = 0 and j M 1 ( z) = 10305 . At the
end of the recursion, the analytical expression for j 0 ( z) is used
to normalize the series.

The forward recursion is used exclusively for computing either


(1)
(2)
h(1) ( z) or h(2) ( z): hn ( z) when { z}  0; and hn ( z) when
{ z} < 0. The seeds are
(1),(2)

h0

( z) =

ieiz
z


(1),(2)

h1

( z) =

1
z


(1),(2)
i h0
( z) (6)

where the upper sign corresponds to the rst superscript.

Spherical Bessel function of the second kind is computed according to


yn ( z) =

(1 )

i [ jn ( z) hn ( z)]
(2 )
i [ jn ( z) hn ( z)]

when { z}  0
when { z} < 0

(7)

The remaining spherical Hankel function is computed according to


(2 )

(1 )

hn ( z ) = 2 j n ( z ) + hn ( z )

(1 )

(2 )

or hn ( z) = 2 jn ( z) hn ( z) (8)

In the recursions, the complex division by z is replaced by complex multiplication by 1/ z, for which the complex division is only
performed once, outside the recursion. This gives more eciency
benet than the alternative recurrences proposed by Boston [2].
4. Properties of the proposed algorithm
4.1. Accuracy and starting order
The accuracy of the computed Bessel function can be assessed
by using Wronskian relations between jn ( z) and hn ( z) [9]:
(1),(2)

(1),(2)

jn ( z)hn1 ( z) jn1 ( z)hn

( z) =

(9)

z2

The number of signicant gures at the n-th order can be estimated according to

 

NSFn = 1 log10  z2 jn ( z)hn1 ( z) jn1 ( z)hn ( z) i 

(10)

666

L.-W. Cai / Computer Physics Communications 182 (2011) 663668

Fig. 4. Starting order M for the backward recursion to achieve desired 14 signicant gures for spherical Bessel function of all orders up to 50.

Fig. 5. Starting order M for the backward recursion to achieve desired 15 signicant gures for spherical Bessel function of all orders up to 50.

In theory, the larger the starting order for the backward recursion, the more accurate the result at the end of the recursion
will be [5]. In practice, it is desirable to use as small as possible a
starting order for a desired accuracy. To determine this starting order M, the following search is performed: starting from M = N + 1,
where N is the maximum order of the Bessel function needed. The
recursions are carried out. Then NSF N is computed according to
Eq. (10), and compared with the target NSF, denoted as NSFt . The
process is repeated while M is increased until NSF N = NSFt .
For NSFt = 13, N = 50, and in the range r  200, Fig. 3 shows
the starting order M as determined by this process, for a series of
phase angles = 0, /6, /4, /3, and /2. It can be approximated by

0.33

M = 1.83 + 4.1 sin0.36 r 0.910.43 sin

+ 9(1

sin ) (11)

Obviously, two other conditions must also be met: M must be no


smaller than N + 1, and M should not exceed its upper limit M max ,

which will be discussed later. Similar curves for NSFt = 14 and 15


are shown in Figs. 3 and 4, respectively. For comparison, M as
approximated by Eq. (11) is also plotted in these gures. Comparing Figs. 3 through 5 shows that M increases by only a small
number (5) when NSFt is raised from 13 to 15. In most cases,
NSF0 = NSF N .
A point of concern is the numerous spikes for the case of = 0
(z is real) in Fig. 5, and two in Fig. 4. They suggest that for a
large range of starting order M, the computation does not reach
NSFt . A loss of signicant gure occurs when | j 0 ( z)| is signicantly smaller than | j 1 ( z)| during the backward recursion, which
is carried over to the normalization factor, and subsequently propagates through the entire series. This only occurs when z is real,
and when sin z approaches zero.
As a remedy, in such cases, j 1 ( z) is used to determine the
normalization factor. This calls for a revision of the proposed algorithm: the larger amplitude of j 0 ( z) and j 1 ( z) is used for normalization. The remedied algorithm shows the compete removal

L.-W. Cai / Computer Physics Communications 182 (2011) 663668

667

Fig. 6. Starting order M for the backward recursion to achieve desired 15 signicant gures using remedied algorithm to counter the loss of signicant gure in j 0 ( z).

Fig. 7. Maximum computable starting order for the backward recursion without causing overow. These curves correspond to the following 4 phase angles: 0,
/2.

/6, /3 and

of the two spikes for the case of NSFt = 14, and the removal of
many spikes, but not all, for the case of NSFt = 15, as shown in
Fig. 6. The remaining spikes are caused by the instances of closeto-zero values of jn ( z) during the recursion. It can be remedied by
monitoring the entire recursion process: when | jn ( z)| is detected
to be signicantly smaller than | jn+1 ( z)|, then, in the next step of
recursion computing jn1 ( z), an alternative backward recurrence
using jn+1 ( z) and jn+2 ( z) is used. However, this is a rather costly
proposition for a relatively small gain. After all, an NSFt of 15 is
approaching the limit of the double-precision oating numbers of
a computer; and an NSFt of 14 is sucient for most applications.

of the usual unity. But this does not prevent the overow entirely.
To determine the maximum order the backward recursion can be
used without causing an overow at the end, the following series
of tests is performed. For a selected starting order, the backward
recursion is run without the normalization, and | j 0 ( z)| is monitored. The smallest starting order that causes | j 0 ( z)| to exceed
10300 is denoted as the maximum starting order M max . The test
results for a wide range of r are shown in Fig. 7 for a series of
phase angles: = 0, /6, /4, /3, and /2. It can be seen that
M max decreases as increases, and that a pure imaginary argument has the smallest M max , which can be approximated by

4.2. Computable range

M max = 235 + 50 | z|

Since the backward recursion progresses in the direction of increasing amplitude, an overow may occur before it reaches the
end. To delay the overow, the starting seed is set as 10305 (or
the smallest oating number the computer can represent) instead

This approximation is shown as the solid black curve in Fig. 7. Note


that M max only ensures no overow during the backward recursion. Overow may still occur during the normalization process.
In such cases, the Bessel function itself exceeds the range representable by the computer.

(12)

668

L.-W. Cai / Computer Physics Communications 182 (2011) 663668

There is a large gap between the minimum starting order M, as


shown in Figs. 3 through 6, and the maximum starting order M max ,
as shown in Fig. 7. For example, at r = 200 and = 0, M 235
(for NSFt = 14) and M max 960. This means that the starting order
can vary in a large range without any notable improvement in the
accuracy. In other words, starting the backward recursion further
out, beyond the minimum starting order M, does not bring much
benet.
However, it is noted that the proposed algorithm has not been
tested for its capability for extreme cases, such as when the magnitudes of real and imaginary parts of the argument differ by several
order of magnitudes. In such extreme cases, extreme care is called
for. A treatment for cylindrical Bessel functions of such arguments
has been proposed by Yousif and Melka [10].
5. Summary
In summary, sources of problems in the existing STH algorithms
for spherical Bessel functions of integer orders and complex arguments have been identied. It was concluded that using the
well-known recurrence relation of Bessel functions in the wrong
direction is the main cause of the problem. A new algorithm,
still based on the highly effective recurrences but in the correct
direction, is proposed. The proposed algorithm uses the recur-

rences only for functions that have monotonic behavior: jn ( z) and


(1)
(2)
hn ( z) or hn ( z), depending on the imaginary part of the argument. Analyses show that the proposed algorithm is capable of
producing spherical Bessel functions of integer order and complex
argument over a large range with results approaching machine accuracy.
Acknowledgement
This work was sponsored by the Oce of Naval Research under
Grant No. N00140910546.
References
[1] L. Shafai, S.J. Towaij, M.A.K. Hamid, Electron. Lett. 6 (1970) 612.
[2] C. Boston, Electron. Lett. 7 (1971) 34.
[3] S. Zhang, J. Jin, Computation of Special Functions, Wiley, New York, 1996,
p. 280.
[4] D.L. Heckmann, S.L. Dvorak, Radio Sci. 36 (2001) 1265.
[5] F.W.J. Olver, D.J. Sookne, Math. Comput. 26 (1972) 941.
[6] C.F. de Toit, IEEE Antennas Propagation Mag. 35 (1993) 19.
[7] C.F. de Toit, IEEE Trans. Atennas Propagation 38 (1990) 1341.
[8] J.P. Mason, Comput. Phys. Comm. 30 (1983) 1.
[9] M. Abramowitz, I.A. Stegun, Handbook of Mathematical Functions, with Formulas, Graphs, and Mathematical Tables, Dover, New York, 1965.
[10] H.A. Yousif, R. Melka, Comput. Phys. Comm. 151 (2003) 25.

You might also like