c5-1 (779485), страница 2
Текст из файла (страница 2)
Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited. To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).Here ∆ is the forward difference operator, i.e.,168Chapter 5.Evaluation of Functionswksp[j+1]=0.5*(wksp[j]+tmp);tmp=dum;}}The powerful Euler technique is not directly applicable to a series of positiveterms.
Occasionally it is useful to convert a series of positive terms into an alternatingseries, just so that the Euler transformation can be used! Van Wijngaarden has givena transformation for accomplishing this [1]:∞Xvr =r=1∞X(−1)r−1 wr(5.1.7)r=1wherewr ≡ vr + 2v2r + 4v4r + 8v8r + · · ·(5.1.8)Equations (5.1.7) and (5.1.8) replace a simple sum by a two-dimensional sum, eachterm in (5.1.7) being itself an infinite sum (5.1.8). This may seem a strange way tosave on work! Since, however, the indices in (5.1.8) increase tremendously rapidly,as powers of 2, it often requires only a few terms to converge (5.1.8) to extraordinaryaccuracy. You do, however, need to be able to compute the vr ’s efficiently for“random” values r.
The standard “updating” tricks for sequential r’s, mentionedabove following equation (5.1.1), can’t be used.Actually, Euler’s transformation is a special case of a more general transformation of power series. Suppose that some known function g(z) has the seriesg(z) =∞Xbn z n(5.1.9)n=0and that you want to sum the new, unknown, series∞Xf(z) =cn b n z n(5.1.10)n=0Then it is not hard to show (see [2]) that equation (5.1.10) can be written asf(z) =∞X[∆(n)c0 ]n=0g(n) nzn!(5.1.11)which often converges much more rapidly. Here ∆(n)c0 is the nth finite-differenceoperator (equation 5.1.6), with ∆(0)c0 ≡ c0 , and g(n) is the nth derivative of g(z).The usual Euler transformation (equation 5.1.5 with n = 0) can be obtained, forexample, by substitutingg(z) =1= 1 − z + z2 − z3 + · · ·1+z(5.1.12)Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)Copyright (C) 1988-1992 by Cambridge University Press.Programs Copyright (C) 1988-1992 by Numerical Recipes Software.Permission is granted for internet users to make one paper copy for their own personal use.
Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited. To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).}wksp[nterm+1]=0.5*(wksp[nterm]+tmp);if (fabs(wksp[nterm+1]) <= fabs(wksp[nterm]))Favorable to increase p,*sum += (0.5*wksp[++nterm]);and the table becomes longer.elseFavorable to increase n,*sum += wksp[nterm+1];the table doesn’t become longer.5.2 Evaluation of Continued Fractions169CITED REFERENCES AND FURTHER READING:Goodwin, E.T.
(ed.) 1961, Modern Computing Methods, 2nd ed. (New York: Philosophical Library), Chapter 13 [van Wijngaarden’s transformations]. [1]Dahlquist, G., and Bjorck, A. 1974, Numerical Methods (Englewood Cliffs, NJ: Prentice-Hall),Chapter 3.Abramowitz, M., and Stegun, I.A. 1964, Handbook of Mathematical Functions, Applied Mathematics Series, Volume 55 (Washington: National Bureau of Standards; reprinted 1968 byDover Publications, New York), §3.6.Mathews, J., and Walker, R.L. 1970, Mathematical Methods of Physics, 2nd ed.
(Reading, MA:W.A. Benjamin/Addison-Wesley), §2.3. [2]5.2 Evaluation of Continued FractionsContinued fractions are often powerful ways of evaluating functions that occurin scientific applications. A continued fraction looks like this:f(x) = b0 +a1b1 +a2b2 +b3 +(5.2.1)a3a4a5b4 +b5 +···Printers prefer to write this asf(x) = b0 +a1a2a3a4a5···b1 + b2 + b3 + b4 + b5 +(5.2.2)In either (5.2.1) or (5.2.2), the a’s and b’s can themselves be functions of x, usuallylinear or quadratic monomials at worst (i.e., constants times x or times x2 ). Forexample, the continued fraction representation of the tangent function istan x =x x2 x2 x2···1− 3− 5− 7−(5.2.3)Continued fractions frequently converge much more rapidly than power seriesexpansions, and in a much larger domain in the complex plane (not necessarilyincluding the domain of convergence of the series, however).
Sometimes thecontinued fraction converges best where the series does worst, although this is notSample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)Copyright (C) 1988-1992 by Cambridge University Press.Programs Copyright (C) 1988-1992 by Numerical Recipes Software.Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited.
To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).into equation (5.1.11), and then setting z = 1.Sometimes you will want to compute a function from a series representationeven when the computation is not efficient. For example, you may be using the valuesobtained to fit the function to an approximating form that you will use subsequently(cf. §5.8).
If you are summing very large numbers of slowly convergent terms, payattention to roundoff errors! In floating-point representation it is more accurate tosum a list of numbers in the order starting with the smallest one, rather than startingwith the largest one. It is even better to group terms pairwise, then in pairs of pairs,etc., so that all additions involve operands of comparable magnitude..















