Thông tin tài liệu:
Occasionally you may wish to know not the value of the interpolating polynomial that passes through a (small!) number of points, but the coefficients of that polynomial. A valid use of the coefficients might be, for example, to compute simultaneous interpolated values
Nội dung trích xuất từ tài liệu:
Interpolation and Extrapolation part 6120 Chapter 3. Interpolation and Extrapolation3.5 Coefficients of the Interpolating Polynomial Occasionally you may wish to know not the value of the interpolating polynomialthat passes through a (small!) number of points, but the coefficients of that poly-nomial. A valid use of the coefficients might be, for example, to computesimultaneous interpolated values of the function and of several of its derivatives (see visit 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). readable files (including this one) to any servercomputer, is strictly prohibited. To order Numerical Recipes books,diskettes, or CDROMs Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copying of machine- 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)§5.3), or to convolve a segment of the tabulated function with some other function,where the moments of that other function (i.e., its convolution with powers of x)are known analytically. However, please be certain that the coefficients are what you need. Generally thecoefficients of the interpolating polynomial can be determined much less accuratelythan its value at a desired abscissa. Therefore it is not a good idea to determine thecoefficients only for use in calculating interpolating values. Values thus calculatedwill not pass exactly through the tabulated points, for example, while valuescomputed by the routines in §3.1–§3.3 will pass exactly through such points. Also, you should not mistake the interpolating polynomial (and its coefficients)for its cousin, the best fit polynomial through a data set. Fitting is a smoothingprocess, since the number of fitted coefficients is typically much less than thenumber of data points. Therefore, fitted coefficients can be accurately and stablydetermined even in the presence of statistical errors in the tabulated values. (See§14.8.) Interpolation, where the number of coefficients and number of tabulatedpoints are equal, takes the tabulated values as perfect. If they in fact contain statisticalerrors, these can be magnified into oscillations of the interpolating polynomial inbetween the tabulated points. As before, we take the tabulated points to be yi ≡ y(xi ). If the interpolatingpolynomial is written as y = c 0 + c1 x + c2 x 2 + · · · + cN x N (3.5.1)then the ci ’s are required to satisfy the linear equation 1 x0 x2 0 · · · x N c0 0 y 0 1 x1 x2 · · · x N c1 y1 . . · . = . 1 1 (3.5.2) . . . . . . . . . . . . . . 1 xN x2 N · · · xNN cN yNThis is a Vandermonde matrix, as described in §2.8. One could in principle solveequation (3.5.2) by standard techniques for linear equations generally (§2.3); howeverthe special method that was derived in §2.8 is more efficient by a large factor, oforder N , so it is much better. Remember that Vandermonde systems can be quite ill-conditioned. In such acase, no numerical method is going to give a very accurate answer. Such cases donot, please note, imply any difficulty in finding interpolated values by the methodsof §3.1, but only difficulty in finding coefficients. Like the routine in §2.8, the following is due to G.B. Rybicki. Note that thearrays are all assumed to be zero-offset. 3.5 Coefficients of the Interpolating Polynomial 121#include nrutil.hvoid polcoe(float x[], float y[], int n, float cof[])Given arrays x[0..n] and y[0..n] containing a tabulated function yi = f (xi ), this routinereturns an array of coefficients cof[0..n], such that yi = j cofj xj . i{ int k,j,i; float phi,ff,b,*s; visit 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). ...