c5-1 (779485)
Текст из файла
Evaluation of Functions5.0 IntroductionThe purpose of this chapter is to acquaint you with a selection of the techniquesthat are frequently used in evaluating functions. In Chapter 6, we will apply andillustrate these techniques by giving routines for a variety of specific functions.The purposes of this chapter and the next are thus mostly in harmony, but thereis nevertheless some tension between them: Routines that are clearest and mostillustrative of the general techniques of this chapter are not always the methods ofchoice for a particular special function.
By comparing this chapter to the next one,you should get some idea of the balance between “general” and “special” methodsthat occurs in practice.Insofar as that balance favors general methods, this chapter should give youideas about how to write your own routine for the evaluation of a function which,while “special” to you, is not so special as to be included in Chapter 6 or thestandard program libraries.CITED REFERENCES AND FURTHER READING:Fike, C.T.
1968, Computer Evaluation of Mathematical Functions (Englewood Cliffs, NJ: PrenticeHall).Lanczos, C. 1956, Applied Analysis; reprinted 1988 (New York: Dover), Chapter 7.5.1 Series and Their ConvergenceEverybody knows that an analytic function can be expanded in the neighborhoodof a point x0 in a power series,f(x) =∞Xak (x − x0 )k(5.1.1)k=0Such series are straightforward to evaluate. You don’t, of course, evaluate the kthpower of x − x0 ab initio for each term; rather you keep the k − 1st power and updateit with a multiply. Similarly, the form of the coefficients a is often such as to makeuse of previous work: Terms like k! or (2k)! can be updated in a multiply or two.165Sample 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).Chapter 5.166Chapter 5.Evaluation of Functionssin x =∞X(−1)k 2k+1x(2k + 1)!(5.1.2)∞ x n X(− 14 x2 )k2k!(k + n)!(5.1.3)k=0Jn (x) =k=0Both of these series converge for all x. But both don’t even start to convergeuntil k |x|; before this, their terms are increasing. This makes these seriesuseless for large x.Accelerating the Convergence of SeriesThere are several tricks for accelerating the rate of convergence of a series (or,equivalently, of a sequence of partial sums).
These tricks will not generally help incases like (5.1.2) or (5.1.3) while the size of the terms is still increasing. For serieswith terms of decreasing magnitude, however, some accelerating methods can bestartlingly good. Aitken’s δ 2 -process is simply a formula for extrapolating the partialsums of a series whose convergence is approximately geometric.
If Sn−1 , Sn , Sn+1are three successive partial sums, then an improved estimate isSn0 ≡ Sn+1 −(Sn+1 − Sn )2Sn+1 − 2Sn + Sn−1(5.1.4)You can also use (5.1.4) with n + 1 and n − 1 replaced by n + p and n − prespectively, for any integer p. If you form the sequence of Si0 ’s, you can apply(5.1.4) a second time to that sequence, and so on. (In practice, this iteration willonly rarely do much for you after the first stage.) Note that equation (5.1.4) shouldbe computed as written; there exist algebraically equivalent forms that are muchmore susceptible to roundoff error.For alternating series (where the terms in the sum alternate in sign), Euler’stransformation can be a powerful tool. Generally it is advisable to do a smallSample 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).How do you know when you have summed enough terms? In practice, theterms had better be getting small fast, otherwise the series is not a good techniqueto use in the first place. While not mathematically rigorous in all cases, standardpractice is to quit when the term you have just added is smaller in magnitude thansome small times the magnitude of the sum thus far accumulated.
(But watch outif isolated instances of ak = 0 are possible!).A weakness of a power series representation is that it is guaranteed not toconverge farther than that distance from x0 at which a singularity is encounteredin the complex plane.
This catastrophe is not usually unexpected: When you finda power series in a book (or when you work one out yourself), you will generallyalso know the radius of convergence. An insidious problem occurs with series thatconverge everywhere (in the mathematical sense), but almost nowhere fast enoughto be useful in a numerical method. Two familiar examples are the sine functionand the Bessel function of the first kind,1675.1 Series and Their Convergencenumber n − 1 of terms directly, then apply the transformation to the rest of the seriesbeginning with the nth term.
The formula (for n even) is∞X(−1)s us = u0 − u1 + u2 . . . − un−1 +s=0∞X(−1)ss=02s+1[∆s un ](5.1.5)∆un ≡ un+1 − un∆2 un ≡ un+2 − 2un+1 + un(5.1.6)∆3 un ≡ un+3 − 3un+2 + 3un+1 − unetc.Of course you don’t actually do the infinite sum on the right-hand side of (5.1.5),but only the first, say, p terms, thus requiring the first p differences (5.1.6) obtainedfrom the terms starting at un .Euler’s transformation can be applied not only to convergent series. In somecases it will produce accurate answers from the first terms of a series that is formallydivergent.
It is widely used in the summation of asymptotic series. In this caseit is generally wise not to sum farther than where the terms start increasing inmagnitude; and you should devise some independent numerical check that the resultsare meaningful.There is an elegant and subtle implementation of Euler’s transformation dueto van Wijngaarden [1]: It incorporates the terms of the original alternating seriesone at a time, in order. For each incorporation it either increases p by 1, equivalentto computing one further difference (5.1.6), or else retroactively increases n by 1,without having to redo all the difference calculations based on the old n value! Thedecision as to which to increase, n or p, is taken in such a way as to make theconvergence most rapid.
Van Wijngaarden’s technique requires only one vector ofsaved partial differences. Here is the algorithm:#include <math.h>void eulsum(float *sum, float term, int jterm, float wksp[])Incorporates into sum the jterm’th term, with value term, of an alternating series. sum isinput as the previous partial sum, and is output as the new partial sum. The first call to thisroutine, with the first term in the series, should be with jterm=1. On the second call, termshould be set to the second term of the series, with sign opposite to that of the first call, andjterm should be 2. And so on.
wksp is a workspace array provided by the calling program,dimensioned at least as large as the maximum number of terms to be incorporated.{int j;static int nterm;float tmp,dum;if (jterm == 1) {nterm=1;*sum=0.5*(wksp[1]=term);} else {tmp=wksp[1];wksp[1]=term;for (j=1;j<=nterm-1;j++) {dum=wksp[j+1];Initialize:Number of saved differences in wksp.Return first estimate.Update saved quantities by van Wijngaarden’s algorithm.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.
Характеристики
Тип файла PDF
PDF-формат наиболее широко используется для просмотра любого типа файлов на любом устройстве. В него можно сохранить документ, таблицы, презентацию, текст, чертежи, вычисления, графики и всё остальное, что можно показать на экране любого устройства. Именно его лучше всего использовать для печати.
Например, если Вам нужно распечатать чертёж из автокада, Вы сохраните чертёж на флешку, но будет ли автокад в пункте печати? А если будет, то нужная версия с нужными библиотеками? Именно для этого и нужен формат PDF - в нём точно будет показано верно вне зависимости от того, в какой программе создали PDF-файл и есть ли нужная программа для его просмотра.















