Chapter 6.Special Functions 6.0 Introduction or call There is nothing particularly special about a special function,except that 11800-472 some person in authority or textbook writer (not the same thing!)has decided to Cambridge bestow the moniker.Special functions are sometimes called higher transcendental NUMERICAL RECIPES IN functions (higher than what?)or functions of mathematical physics (but they occur in server other fields also)or functions that satisfy certain frequently occurring second-order differential equations (but not all special functions do).One might simply call them >二 compu Press. C:THEA "useful functions"and let it go at that;it is surely only a matter of taste which functions we have chosen to include in this chapter. Good commercially available program libraries,such as NAG or IMSL,contain routines for a number of special functions.These routines are intended for users who 马 will have no idea what goes on inside them.Such state of the art "black boxes"are often very messy things,full of branches to completely different methods depending SCIENTIFIC on the value of the calling arguments.Black boxes have,or should have,careful 6 control of accuracy,to some stated uniform precision in all regimes. We will not be quite so fastidious in our examples,in part because we want to illustrate techniques from Chapter 5,and in part because we want you to understand what goes on in the routines presented.Some of our routines have an accuracy parameter that can be made as small as desired,while others(especially r Numerical those involving polynomial fits)give only a certain accuracy,one that we believe serviceable(typically six significant figures or more).We do not certify that the Recipes routines are perfect black boxes.We do hope that,if you ever encounter trouble in a routine,you will be able to diagnose and correct the problem on the basis of ecipes the information that we have given. In short,the special function routines of this chapter are meant to be used- we use them all the time-but we also want you to be prepared to understand North Software. their inner workings. America) CITED REFERENCES AND FURTHER READING: visit website machine- Abramowitz,M.,and Stegun,I.A.1964.Handbook of Mathematical Functions,Applied Mathe- matics Series,Volume 55 (Washington:National Bureau of Standards;reprinted 1968 by Dover Publications,New York)[full of useful numerical approximations to a great variety of functions]. IMSL Sfun/Library Users Manual(IMSL Inc.,2500 CityWest Boulevard,Houston TX 77042) NAG Fortran Library (Numerical Algorithms Group,256 Banbury Road,Oxford OX27DE,U.K.). Chapter S. 212
Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). Chapter 6. Special Functions 6.0 Introduction There is nothing particularly special about a special function, except that some person in authority or textbook writer (not the same thing!) has decided to bestow the moniker. Special functions are sometimes called higher transcendental functions (higher than what?) or functions of mathematical physics (but they occur in other fields also) or functions that satisfy certain frequently occurring second-order differential equations (but not all special functions do). One might simply call them “useful functions” and let it go at that; it is surely only a matter of taste which functions we have chosen to include in this chapter. Good commercially available program libraries, such as NAG or IMSL, contain routines for a number of special functions. These routines are intended for users who will have no idea what goes on inside them. Such state of the art “black boxes” are often very messy things, full of branches to completely different methods depending on the value of the calling arguments. Black boxes have, or should have, careful control of accuracy, to some stated uniform precision in all regimes. We will not be quite so fastidious in our examples, in part because we want to illustrate techniques from Chapter 5, and in part because we want you to understand what goes on in the routines presented. Some of our routines have an accuracy parameter that can be made as small as desired, while others (especially those involving polynomial fits) give only a certain accuracy, one that we believe serviceable (typically six significant figures or more). We do not certify that the routines are perfect black boxes. We do hope that, if you ever encounter trouble in a routine, you will be able to diagnose and correct the problem on the basis of the information that we have given. In short, the special function routines of this chapter are meant to be used — we use them all the time — but we also want you to be prepared to understand their inner workings. CITED REFERENCES AND FURTHER READING: Abramowitz, M., and Stegun, I.A. 1964, Handbook of Mathematical Functions, Applied Mathematics Series, Volume 55 (Washington: National Bureau of Standards; reprinted 1968 by Dover Publications, New York) [full of useful numerical approximations to a great variety of functions]. IMSL Sfun/Library Users Manual (IMSL Inc., 2500 CityWest Boulevard, Houston TX 77042). NAG Fortran Library (Numerical Algorithms Group, 256 Banbury Road, Oxford OX27DE, U.K.), Chapter S. 212
6.1 Gamma,Beta,and Related Functions 213 Hart,J.F.,et al.1968,Computer Approximations (New York:Wiley). Hastings,C.1955,Approximations for Digita/Computers(Princeton:Princeton University Press). Luke,Y.L.1975,Mathematical Functions and Their Approximations(New York:Academic Press). 6.1 Gamma Function,Beta Function,Factorials, Binomial Coefficients ://www.nr The gamma function is defined by the integral T(z)= t=-le-tdt (6.1.1) When the argument z is an integer,the gamma function is just the familiar factorial function,but offset by one, n!=T(n+1) (6.1.2) The gamma function satisfies the recurrence relation 2为 9 T(z+1)=2T(z) (6.1.3) If the function is known for arguments z>1 or,more generally,in the half complex 0a是g%9 plane Re(z)>1 it can be obtained for z0) You can see that this is a sort of take-off on Stirling's approximation,but with a series of corrections that take into account the first few poles in the left complex plane.The constant co is very nearly equal to 1.The error term is parametrized by e. For5,N-6,and a certain set ofc's,the error is smaller than e0
6.1 Gamma, Beta, and Related Functions 213 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). Hart, J.F., et al. 1968, Computer Approximations (New York: Wiley). Hastings, C. 1955, Approximations for Digital Computers (Princeton: Princeton University Press). Luke, Y.L. 1975, Mathematical Functions and Their Approximations (New York: Academic Press). 6.1 Gamma Function, Beta Function, Factorials, Binomial Coefficients The gamma function is defined by the integral Γ(z) = ∞ 0 t z−1e−t dt (6.1.1) When the argument z is an integer, the gamma function is just the familiar factorial function, but offset by one, n! = Γ(n + 1) (6.1.2) The gamma function satisfies the recurrence relation Γ(z + 1) = zΓ(z) (6.1.3) If the function is known for arguments z > 1 or, more generally, in the half complex plane Re(z) > 1 it can be obtained for z 0) (6.1.5) You can see that this is a sort of take-off on Stirling’s approximation, but with a series of corrections that take into account the first few poles in the left complex plane. The constant c0 is very nearly equal to 1. The error term is parametrized by . For γ = 5, N = 6, and a certain set of c’s, the error is smaller than || 0.