|
Packit |
67cb25 |
.. index:: special functions
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
*****************
|
|
Packit |
67cb25 |
Special Functions
|
|
Packit |
67cb25 |
*****************
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
This chapter describes the GSL special function library. The library
|
|
Packit |
67cb25 |
includes routines for calculating the values of Airy functions, Bessel
|
|
Packit |
67cb25 |
functions, Clausen functions, Coulomb wave functions, Coupling
|
|
Packit |
67cb25 |
coefficients, the Dawson function, Debye functions, Dilogarithms,
|
|
Packit |
67cb25 |
Elliptic integrals, Jacobi elliptic functions, Error functions,
|
|
Packit |
67cb25 |
Exponential integrals, Fermi-Dirac functions, Gamma functions,
|
|
Packit |
67cb25 |
Gegenbauer functions, Hermite polynomials and functions, Hypergeometric functions, Laguerre functions,
|
|
Packit |
67cb25 |
Legendre functions and Spherical Harmonics, the Psi (Digamma) Function,
|
|
Packit |
67cb25 |
Synchrotron functions, Transport functions, Trigonometric functions and
|
|
Packit |
67cb25 |
Zeta functions. Each routine also computes an estimate of the numerical
|
|
Packit |
67cb25 |
error in the calculated value of the function.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The functions in this chapter are declared in individual header files,
|
|
Packit |
67cb25 |
such as :file:`gsl_sf_airy.h`, :file:`gsl_sf_bessel.h`, etc. The complete
|
|
Packit |
67cb25 |
set of header files can be included using the file :file:`gsl_sf.h`.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Usage
|
|
Packit |
67cb25 |
=====
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The special functions are available in two calling conventions, a
|
|
Packit |
67cb25 |
*natural form* which returns the numerical value of the function and
|
|
Packit |
67cb25 |
an *error-handling form* which returns an error code. The two types
|
|
Packit |
67cb25 |
of function provide alternative ways of accessing the same underlying
|
|
Packit |
67cb25 |
code.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The *natural form* returns only the value of the function and can be
|
|
Packit |
67cb25 |
used directly in mathematical expressions. For example, the following
|
|
Packit |
67cb25 |
function call will compute the value of the Bessel function
|
|
Packit |
67cb25 |
:math:`J_0(x)`::
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
double y = gsl_sf_bessel_J0 (x);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
There is no way to access an error code or to estimate the error using
|
|
Packit |
67cb25 |
this method. To allow access to this information the alternative
|
|
Packit |
67cb25 |
error-handling form stores the value and error in a modifiable argument::
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
gsl_sf_result result;
|
|
Packit |
67cb25 |
int status = gsl_sf_bessel_J0_e (x, &result);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The error-handling functions have the suffix :code:`_e`. The returned
|
|
Packit |
67cb25 |
status value indicates error conditions such as overflow, underflow or
|
|
Packit |
67cb25 |
loss of precision. If there are no errors the error-handling functions
|
|
Packit |
67cb25 |
return :code:`GSL_SUCCESS`.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The gsl_sf_result struct
|
|
Packit |
67cb25 |
========================
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The error handling form of the special functions always calculate an
|
|
Packit |
67cb25 |
error estimate along with the value of the result. Therefore,
|
|
Packit |
67cb25 |
structures are provided for amalgamating a value and error estimate.
|
|
Packit |
67cb25 |
These structures are declared in the header file :file:`gsl_sf_result.h`.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The following struct contains value and error fields.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. type:: gsl_sf_result
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
::
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
typedef struct
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
double val;
|
|
Packit |
67cb25 |
double err;
|
|
Packit |
67cb25 |
} gsl_sf_result;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The field :data:`val` contains the value and the field :data:`err` contains
|
|
Packit |
67cb25 |
an estimate of the absolute error in the value.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
In some cases, an overflow or underflow can be detected and handled by a
|
|
Packit |
67cb25 |
function. In this case, it may be possible to return a scaling exponent
|
|
Packit |
67cb25 |
as well as an error/value pair in order to save the result from
|
|
Packit |
67cb25 |
exceeding the dynamic range of the built-in types. The
|
|
Packit |
67cb25 |
following struct contains value and error fields as well
|
|
Packit |
67cb25 |
as an exponent field such that the actual result is obtained as
|
|
Packit |
67cb25 |
:code:`result * 10^(e10)`.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. type:: gsl_sf_result_e10
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
::
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
typedef struct
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
double val;
|
|
Packit |
67cb25 |
double err;
|
|
Packit |
67cb25 |
int e10;
|
|
Packit |
67cb25 |
} gsl_sf_result_e10;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Modes
|
|
Packit |
67cb25 |
=====
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The goal of the library is to achieve double precision accuracy wherever
|
|
Packit |
67cb25 |
possible. However the cost of evaluating some special functions to
|
|
Packit |
67cb25 |
double precision can be significant, particularly where very high order
|
|
Packit |
67cb25 |
terms are required. In these cases a :code:`mode` argument, of type
|
|
Packit |
67cb25 |
:type:`gsl_mode_t` allows the
|
|
Packit |
67cb25 |
accuracy of the function to be reduced in order to improve performance.
|
|
Packit |
67cb25 |
The following precision levels are available for the mode argument,
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. type:: gsl_mode_t
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. macro:: GSL_PREC_DOUBLE
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Double-precision, a relative accuracy of approximately :math:`2 * 10^{-16}`.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. macro:: GSL_PREC_SINGLE
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Single-precision, a relative accuracy of approximately :math:`10^{-7}`.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. macro:: GSL_PREC_APPROX
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Approximate values, a relative accuracy of approximately :math:`5 * 10^{-4}`.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The approximate mode provides the fastest evaluation at the lowest
|
|
Packit |
67cb25 |
accuracy.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Airy Functions and Derivatives
|
|
Packit |
67cb25 |
==============================
|
|
Packit |
67cb25 |
.. include:: specfunc-airy.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Bessel Functions
|
|
Packit |
67cb25 |
================
|
|
Packit |
67cb25 |
.. include:: specfunc-bessel.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Clausen Functions
|
|
Packit |
67cb25 |
=================
|
|
Packit |
67cb25 |
.. include:: specfunc-clausen.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Coulomb Functions
|
|
Packit |
67cb25 |
=================
|
|
Packit |
67cb25 |
.. include:: specfunc-coulomb.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Coupling Coefficients
|
|
Packit |
67cb25 |
=====================
|
|
Packit |
67cb25 |
.. include:: specfunc-coupling.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Dawson Function
|
|
Packit |
67cb25 |
===============
|
|
Packit |
67cb25 |
.. include:: specfunc-dawson.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Debye Functions
|
|
Packit |
67cb25 |
===============
|
|
Packit |
67cb25 |
.. include:: specfunc-debye.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. _dilog-function:
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Dilogarithm
|
|
Packit |
67cb25 |
===========
|
|
Packit |
67cb25 |
.. include:: specfunc-dilog.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Elementary Operations
|
|
Packit |
67cb25 |
=====================
|
|
Packit |
67cb25 |
.. include:: specfunc-elementary.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Elliptic Integrals
|
|
Packit |
67cb25 |
==================
|
|
Packit |
67cb25 |
.. include:: specfunc-ellint.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Elliptic Functions (Jacobi)
|
|
Packit |
67cb25 |
===========================
|
|
Packit |
67cb25 |
.. include:: specfunc-elljac.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Error Functions
|
|
Packit |
67cb25 |
===============
|
|
Packit |
67cb25 |
.. include:: specfunc-erf.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Exponential Functions
|
|
Packit |
67cb25 |
=====================
|
|
Packit |
67cb25 |
.. include:: specfunc-exp.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Exponential Integrals
|
|
Packit |
67cb25 |
=====================
|
|
Packit |
67cb25 |
.. include:: specfunc-expint.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Fermi-Dirac Function
|
|
Packit |
67cb25 |
====================
|
|
Packit |
67cb25 |
.. include:: specfunc-fermi-dirac.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Gamma and Beta Functions
|
|
Packit |
67cb25 |
========================
|
|
Packit |
67cb25 |
.. include:: specfunc-gamma.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Gegenbauer Functions
|
|
Packit |
67cb25 |
====================
|
|
Packit |
67cb25 |
.. include:: specfunc-gegenbauer.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Hermite Polynomials and Functions
|
|
Packit |
67cb25 |
=================================
|
|
Packit |
67cb25 |
.. include:: specfunc-hermite.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Hypergeometric Functions
|
|
Packit |
67cb25 |
========================
|
|
Packit |
67cb25 |
.. include:: specfunc-hyperg.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. _laguerre-functions:
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Laguerre Functions
|
|
Packit |
67cb25 |
==================
|
|
Packit |
67cb25 |
.. include:: specfunc-laguerre.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Lambert W Functions
|
|
Packit |
67cb25 |
===================
|
|
Packit |
67cb25 |
.. include:: specfunc-lambert.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Legendre Functions and Spherical Harmonics
|
|
Packit |
67cb25 |
==========================================
|
|
Packit |
67cb25 |
.. include:: specfunc-legendre.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Logarithm and Related Functions
|
|
Packit |
67cb25 |
===============================
|
|
Packit |
67cb25 |
.. include:: specfunc-log.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Mathieu Functions
|
|
Packit |
67cb25 |
=================
|
|
Packit |
67cb25 |
.. include:: specfunc-mathieu.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Power Function
|
|
Packit |
67cb25 |
==============
|
|
Packit |
67cb25 |
.. include:: specfunc-pow-int.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Psi (Digamma) Function
|
|
Packit |
67cb25 |
======================
|
|
Packit |
67cb25 |
.. include:: specfunc-psi.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Synchrotron Functions
|
|
Packit |
67cb25 |
=====================
|
|
Packit |
67cb25 |
.. include:: specfunc-synchrotron.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Transport Functions
|
|
Packit |
67cb25 |
===================
|
|
Packit |
67cb25 |
.. include:: specfunc-transport.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Trigonometric Functions
|
|
Packit |
67cb25 |
=======================
|
|
Packit |
67cb25 |
.. include:: specfunc-trig.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Zeta Functions
|
|
Packit |
67cb25 |
==============
|
|
Packit |
67cb25 |
.. include:: specfunc-zeta.rst
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Examples
|
|
Packit |
67cb25 |
========
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The following example demonstrates the use of the error handling form of
|
|
Packit |
67cb25 |
the special functions, in this case to compute the Bessel function
|
|
Packit |
67cb25 |
:math:`J_0(5.0)`,
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. include:: examples/specfun_e.c
|
|
Packit |
67cb25 |
:code:
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Here are the results of running the program,
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. include:: examples/specfun_e.txt
|
|
Packit |
67cb25 |
:code:
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The next program computes the same quantity using the natural form of
|
|
Packit |
67cb25 |
the function. In this case the error term :data:`result.err` and return
|
|
Packit |
67cb25 |
status are not accessible.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. include:: examples/specfun.c
|
|
Packit |
67cb25 |
:code:
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The results of the function are the same,
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. include:: examples/specfun.txt
|
|
Packit |
67cb25 |
:code:
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
References and Further Reading
|
|
Packit |
67cb25 |
==============================
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The library follows the conventions of the following book where possible,
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* Handbook of Mathematical Functions, edited by Abramowitz & Stegun,
|
|
Packit |
67cb25 |
Dover, ISBN 0486612724.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
The following papers contain information on the algorithms used
|
|
Packit |
67cb25 |
to compute the special functions,
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
.. index:: MISCFUN
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* Allan J. MacLeod, MISCFUN: A software package to compute uncommon
|
|
Packit |
67cb25 |
special functions. ACM Trans. Math. Soft., vol.: 22,
|
|
Packit |
67cb25 |
1996, 288--301
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* G.N. Watson, A Treatise on the Theory of Bessel Functions,
|
|
Packit |
67cb25 |
2nd Edition (Cambridge University Press, 1944).
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* G. Nemeth, Mathematical Approximations of Special Functions,
|
|
Packit |
67cb25 |
Nova Science Publishers, ISBN 1-56072-052-2
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* B.C. Carlson, Special Functions of Applied Mathematics (1977)
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* N. M. Temme, Special Functions: An Introduction to the Classical
|
|
Packit |
67cb25 |
Functions of Mathematical Physics (1996), ISBN 978-0471113133.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* W.J. Thompson, Atlas for Computing Mathematical Functions, John Wiley & Sons,
|
|
Packit |
67cb25 |
New York (1997).
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* Y.Y. Luke, Algorithms for the Computation of Mathematical Functions, Academic
|
|
Packit |
67cb25 |
Press, New York (1977).
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* S. A. Holmes and W. E. Featherstone, A unified approach to the Clenshaw
|
|
Packit |
67cb25 |
summation and the recursive computation of very high degree and order
|
|
Packit |
67cb25 |
normalised associated Legendre functions, Journal of Geodesy, 76,
|
|
Packit |
67cb25 |
pg. 279-299, 2002.
|