NAG Library s - Approximations of Special Functions
|
Scope of the Chapter
|
|
This chapter is concerned with the provision of some commonly occurring physical and mathematical functions.
|
|
Background to the Problems
|
|
The majority of the functions in this chapter approximate real-valued functions of a single real argument, and the techniques involved are described in Section [Functions of a Single Real Argument]. In addition the chapter contains functions for elliptic integrals (see Section [Approximations to Elliptic Integrals]), Bessel and Airy functions of a complex argument (see Section [Bessel and Airy Functions of a Complex Argument]), exponential of a complex argument, and complementary error function of a complex argument.
|
Functions of a Single Real Argument
|
|
Most of the functions for functions of a single real argument have been based on truncated Chebyshev expansions. This method of approximation was adopted as a compromise between the conflicting requirements of efficiency and ease of implementation on many different machine ranges. For details of the reasons behind this choice and the production and testing procedures followed in constructing this chapter see Schonfelder (1976).
Basically, if the function to be approximated is , then for an approximation of the form
is used ( denotes, according to the usual convention, a summation in which the first term is halved), where is some suitable auxiliary function which extracts any singularities, asymptotes and, if possible, zeros of the function in the range in question and is a mapping of the general range to the specific range [ ] required by the Chebyshev polynomials, . For a detailed description of the properties of the Chebyshev polynomials see Clenshaw (1962) and Fox and Parker (1968).
The essential property of these polynomials for the purposes of function approximation is that oscillates between and it takes its extreme values times in the interval [ ]. Therefore, provided the coefficients decrease in magnitude sufficiently rapidly the error made by truncating the Chebyshev expansion after terms is approximately given by
That is, the error oscillates between and takes its extreme value times in the interval in question. Now this is just the condition that the approximation be a mini-max representation, one which minimizes the maximum error. By suitable choice of the interval, [ ], the auxiliary function, , and the mapping of the independent variable, , it is almost always possible to obtain a Chebyshev expansion with rapid convergence and hence truncations that provide near mini-max polynomial approximations to the required function. The difference between the true mini-max polynomial and the truncated Chebyshev expansion is seldom sufficiently great enough to be of significance.
The evaluation of the Chebyshev expansions follows one of two methods. The first and most efficient, and hence the most commonly used, works with the equivalent simple polynomial. The second method, which is used on the few occasions when the first method proves to be unstable, is based directly on the truncated Chebyshev-series, and uses backward recursion to evaluate the sum. For the first method, a suitably truncated Chebyshev expansion (truncation is chosen so that the error is less than the machine precision) is converted to the equivalent simple polynomial. That is, we evaluate the set of coefficients such that
The polynomial can then be evaluated by the efficient Horner's method of nested multiplications,
This method of evaluation results in efficient functions but for some expansions there is considerable loss of accuracy due to cancellation effects. In these cases the second method is used. It is well known that if
then
and this is always stable. This method is most efficiently implemented by using three variables cyclically and explicitly constructing the recursion.
That is,
The auxiliary functions used are normally functions compounded of simple polynomial (usually linear) factors extracting zeros, and the primary compiler-provided functions, sin, cos, ln, exp, sqrt, which extract singularities and/or asymptotes or in some cases basic oscillatory behaviour, leaving a smooth well-behaved function to be approximated by the Chebyshev expansion which can therefore be rapidly convergent.
The mappings of [ ] to [ ] used range from simple linear mappings to the case when is infinite, and considerable improvement in convergence can be obtained by use of a bilinear form of mapping. Another common form of mapping is used when the function is even; that is, it involves only even powers in its expansion. In this case an approximation over the whole interval [ ] can be provided using a mapping . This embodies the evenness property but the expansion in involves all powers and hence removes the necessity of working with an expansion with half its coefficients zero.
For many of the functions an analysis of the error in principle is given, namely, if and are the absolute errors in function and argument and and are the corresponding relative errors, then
If we ignore errors that arise in the argument of the function by propagation of data errors, etc., and consider only those errors that result from the fact that a real number is being represented in the computer in floating-point form with finite precision, then is bounded and this bound is independent of the magnitude of . For example, on an 11-digit machine
(This of course implies that the absolute error is also bounded but the bound is now dependent on .) However, because of this the last two relations above are probably of more interest. If possible the relative error propagation is discussed; that is, the behaviour of the error amplification factor is described, but in some cases, such as near zeros of the function which cannot be extracted explicitly, absolute error in the result is the quantity of significance and here the factor is described. In general, testing of the functions has shown that their error behaviour follows fairly well these theoretical error behaviours. In regions where the error amplification factors are less than or of the order of one, the errors are slightly larger than the above predictions. The errors are here limited largely by the finite precision of arithmetic in the machine, but is normally no more than a few times greater than the bound on . In regions where the amplification factors are large, of order ten or greater, the theoretical analysis gives a good measure of the accuracy obtainable.
It should be noted that the definitions and notations used for the functions in this chapter are all taken from Abramowitz and Stegun (1972). You are strongly recommended to consult this book for details before using the functions in this chapter.
|
|
Approximations to Elliptic Integrals
|
|
Four functions provided here are symmetrised variants of the classical (Legendre) elliptic integrals. These alternative definitions have been suggested by Carlson (1965), Carlson (1977a) and Carlson (1977b) and he also developed the basic algorithms used in this chapter.
The standard Carlson integral of the first kind is represented by
where and at most one may be equal to zero.
The normalization factor, , is chosen so as to make
If any two of the variables are equal, degenerates into the second function
where the argument restrictions are now and .
This function is related to the logarithm or inverse hyperbolic functions if , and to the inverse circular functions if .
The Carlson integral of the second kind is defined by
with , and , but only one of or may be zero.
The function is a degenerate special case of the Carlson integral of the third kind
with and with at most one equality holding. Thus . The normalization of both these functions is chosen so that
The algorithms used for all these functions are based on duplication theorems. These allow a recursion system to be established which constructs a new set of arguments from the old using a combination of arithmetic and geometric means. The value of the function at the original arguments can then be simply related to the value at the new arguments. These recursive reductions are used until the arguments differ from the mean by an amount small enough for a Taylor series about the mean to give sufficient accuracy when retaining terms of order less than six. Each step of the recurrences reduces the difference from the mean by a factor of four, and as the truncation error is of order six, the truncation error goes like , where is the number of iterations.
The above forms can be related to the more traditional canonical forms (see Section 17.2 in Abramowitz and Stegun (1972)), as follows.
If we write , where , we have
the classical elliptic integral of the first kind:
the classical elliptic integral of the second kind:
the classical elliptic integral of the third kind:
Also the classical complete elliptic integral of the first kind:
the complete elliptic integral of the second kind:
For convenience, Chapter s contains functions to evaluate classical and Carlson elliptic integrals.
|
|
|
Recommendations on Choice and Use of Available Functions
|
|
|
Elliptic Integrals
|
|
IMPORTANT ADVICE: users who encounter elliptic integrals in the course of their work are strongly recommended to look at transforming their analysis directly to one of the Carlson forms, rather than to the traditional canonical Legendre forms. In general, the extra symmetry of the Carlson forms is likely to simplify the analysis, and these symmetric forms are much more stable to calculate.
The function s21bac (nag_elliptic_integral_rc) for is largely included as an auxiliary to the other functions for elliptic integrals. This integral essentially calculates elementary functions, e.g.,
In general this method of calculating these elementary functions is not recommended as there are usually much more efficient specific functions available in the Library. However, s21bac (nag_elliptic_integral_rc) may be used, for example, to compute when is close to 1, without the loss of significant figures that occurs when and are computed separately.
|
|
|
Index
|
|
Airy function,
or , complex argument, optionally scaled: s17dgc (nag_complex_airy_ai)
, real argument: s17agc (nag_airy_ai)
, real argument: s17ajc (nag_airy_ai_deriv)
or , complex argument, optionally scaled: s17dhc (nag_complex_airy_bi)
, real argument: s17ahc (nag_airy_bi)
, real argument: s17akc (nag_airy_bi_deriv)
Arccosh,
inverse hyperbolic cosine: s11acc (nag_arccosh)
Arcsinh,
inverse hyperbolic sine: s11abc (nag_arcsinh)
Arctanh,
inverse hyperbolic tangent: s11aac (nag_arctanh)
Bessel function,
, real argument: s17aec (nag_bessel_j0)
, real argument: s17afc (nag_bessel_j1)
, real argument: s18gkc (nag_complex_bessel_j_seq)
, complex argument, optionally scaled: s17dec (nag_complex_bessel_j)
, real argument: s17acc (nag_bessel_y0)
, real argument: s17adc (nag_bessel_y1)
, complex argument, optionally scaled: s17dcc (nag_complex_bessel_y)
Complement of the Cumulative Normal distribution: s15acc (nag_cumul_normal_complem)
Complement of the Error function,
complex argument, scaled: s15ddc (nag_complex_erfc)
real argument: s15adc (nag_erfc)
Cosine Integral: s13acc (nag_cos_integral)
Cosine,
hyperbolic: s10acc (nag_cosh)
Cumulative Normal distribution function: s15abc (nag_cumul_normal)
Dawson's Integral: s15afc (nag_dawson)
Digamma function, scaled: s14adc (nag_polygamma_deriv)
Elliptic functions, Jacobian, sn, cn, dn
complex argument: s21cbc (nag_jacobian_elliptic)
real argument: s21cac (nag_real_jacobian_elliptic)
Elliptic integral,
general,
of 2nd kind, : s21dac (nag_elliptic_integral_f)
symmetrised,
degenerate of 1st kind, : s21bac (nag_elliptic_integral_rc)
of 1st kind, : s21bbc (nag_elliptic_integral_rf)
of 2nd kind, : s21bcc (nag_elliptic_integral_rd)
of 3rd kind, : s21bdc (nag_elliptic_integral_rj)
Erf,
real argument: s15aec (nag_erf)
Erfc,
complex argument, scaled: s15ddc (nag_complex_erfc)
real argument: s15adc (nag_erfc)
Error function,
real argument: s15aec (nag_erf)
Exponential Integral: s13aac (nag_exp_integral)
Fresnel Integral,
: s20adc (nag_fresnel_c)
: s20acc (nag_fresnel_s)
Gamma function: s14aac (nag_gamma)
Gamma function,
incomplete: s14bac (nag_incomplete_gamma)
Generalized Factorial function: s14aac (nag_gamma)
Hankel function or ,
complex argument, optionally scaled: s17dlc (nag_complex_hankel)
Jacobian elliptic functions, sn, cn, dn,
complex argument: s21cbc (nag_jacobian_elliptic)
real argument: s21cac (nag_real_jacobian_elliptic)
Jacobian theta functions ,
real argument: s21ccc (nag_jacobian_theta)
Kelvin function,
: s19aac (nag_kelvin_ber)
: s19abc (nag_kelvin_bei)
: s19acc (nag_kelvin_ker)
: s19adc (nag_kelvin_kei)
Legendre functions of 1st kind , : s22aac (nag_legendre_p)
Logarithm of : s01bac (nag_shifted_log)
Logarithm of Gamma function,
complex: s14agc (nag_complex_log_gamma)
real: s14abc (nag_log_gamma)
Modified Bessel function(s),
, real argument: s18aec (nag_bessel_i0)
, real argument: s18afc (nag_bessel_i1)
or , real argument: s18ejc (nag_bessel_i_alpha)
, complex argument, optionally scaled: s18dec (nag_complex_bessel_i)
, real argument: s18eec (nag_bessel_i_nu)
or , real argument: s18ekc (nag_bessel_j_alpha)
, real argument: s18acc (nag_bessel_k0)
, real argument: s18adc (nag_bessel_k1)
, real argument: s18egc (nag_bessel_k_alpha)
, complex argument, optionally scaled: s18dcc (nag_complex_bessel_k)
, real argument: s18efc (nag_bessel_k_nu)
Polygamma function,
, real : s14aec (nag_real_polygamma)
, complex : s14afc (nag_complex_polygamma)
Psi function: s14acc (nag_polygamma_fun)
Psi function and derivatives, scaled: s14adc (nag_polygamma_deriv)
Scaled modified Bessel function(s),
, real argument: s18ecc (nag_bessel_i_nu_scaled)
, real argument: s18cec (nag_bessel_i0_scaled)
, real argument: s18cfc (nag_bessel_i1_scaled)
, real argument: s18ccc (nag_bessel_k0_scaled)
, real argument: s18cdc (nag_bessel_k1_scaled)
, real argument: s18edc (nag_bessel_k_nu_scaled)
, real argument: s18ehc (nag_bessel_k_alpha_scaled)
Sine Integral: s13adc (nag_sin_integral)
Sine,
hyperbolic: s10abc (nag_sinh)
Tangent,
hyperbolic: s10aac (nag_tanh)
Trigamma function, scaled: s14adc (nag_polygamma_deriv)
Zeros of Bessel functions , , , : s17alc (nag_bessel_zeros)
|
|
See Also
|
|
Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Carlson B C (1965) On computing elliptic integrals and functions J. Math. Phys. 44 36–51
Carlson B C (1977a) Elliptic integrals of the first kind SIAM J. Math. Anal. 8 231–242
Carlson B C (1977b) Special Functions of Applied Mathematics Academic Press
Clenshaw C W (1962) Mathematical tables Chebyshev Series for Mathematical Functions HMSO
Fox L and Parker I B (1968) Chebyshev Polynomials in Numerical Analysis Oxford University Press
Schonfelder J L (1976) The production of special function routines for a multi-machine library Softw. Pract. Exper. 6 (1)
NAG Toolbox Overview.
NAG Web Site.
|
|