c9-4 (779534)
Текст из файла
362Chapter 9.Root Finding and Nonlinear Sets of Equations}a=b;fa=fb;if (fabs(d) > tol1)b += d;elseb += SIGN(tol1,xm);fb=(*func)(b);Move last best guess to a.Evaluate new trial root.}CITED REFERENCES AND FURTHER READING:Brent, R.P. 1973, Algorithms for Minimization without Derivatives (Englewood Cliffs, NJ: PrenticeHall), Chapters 3, 4. [1]Forsythe, G.E., Malcolm, M.A., and Moler, C.B. 1977, Computer Methods for MathematicalComputations (Englewood Cliffs, NJ: Prentice-Hall), §7.2.9.4 Newton-Raphson Method Using DerivativePerhaps the most celebrated of all one-dimensional root-finding routines is Newton’s method, also called the Newton-Raphson method.
This method is distinguishedfrom the methods of previous sections by the fact that it requires the evaluationof both the function f(x), and the derivative f 0 (x), at arbitrary points x. TheNewton-Raphson formula consists geometrically of extending the tangent line at acurrent point xi until it crosses zero, then setting the next guess xi+1 to the abscissaof that zero-crossing (see Figure 9.4.1). Algebraically, the method derives from thefamiliar Taylor series expansion of a function in the neighborhood of a point,f(x + δ) ≈ f(x) + f 0 (x)δ +f 00 (x) 2δ + ....2(9.4.1)For small enough values of δ, and for well-behaved functions, the terms beyondlinear are unimportant, hence f(x + δ) = 0 impliesδ=−f(x).f 0 (x)(9.4.2)Newton-Raphson is not restricted to one dimension.
The method readilygeneralizes to multiple dimensions, as we shall see in §9.6 and §9.7, below.Far from a root, where the higher-order terms in the series are important, theNewton-Raphson formula can give grossly inaccurate, meaningless corrections. Forinstance, the initial guess for the root might be so far from the true root as to letthe search interval include a local maximum or minimum of the function.
This canbe death to the method (see Figure 9.4.2). If an iteration places a trial guess nearsuch a local extremum, so that the first derivative nearly vanishes, then NewtonRaphson sends its solution off to limbo, with vanishingly small hope of recovery.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).}nrerror("Maximum number of iterations exceeded in zbrent");return 0.0;Never get here.23xFigure 9.4.1. Newton’s method extrapolates the local derivative to find the next estimate of the root. Inthis example it works well and converges quadratically.f(x)1xFigure 9.4.2. Unfortunate case where Newton’s method encounters a local extremum and shoots off toouter space.
Here bracketing bounds, as in rtsafe, would save the day.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).233639.4 Newton-Raphson Method Using Derivativef(x)1364Chapter 9.Root Finding and Nonlinear Sets of Equationsf(x)12Figure 9.4.3.
Unfortunate case where Newton’s method enters a nonconvergent cycle. This behavioris often encountered when the function f is obtained, in whole or in part, by table interpolation. Witha better initial guess, the method would have succeeded.Like most powerful tools, Newton-Raphson can be destructive used in inappropriatecircumstances. Figure 9.4.3 demonstrates another possible pathology.Why do we call Newton-Raphson powerful? The answer lies in its rate ofconvergence: Within a small distance of x the function and its derivative areapproximately:f 00 (x)+ · · ·,20000f (x + ) = f (x) + f (x) + · · ·f(x + ) = f(x) + f 0 (x) + 2(9.4.3)By the Newton-Raphson formula,xi+1 = xi −f(xi ),f 0 (xi )(9.4.4)i+1 = i −f(xi ).f 0 (xi )(9.4.5)so thatWhen a trial solution xi differs from the true root by i , we can use (9.4.3) to expressf(xi ), f 0 (xi ) in (9.4.4) in terms of i and derivatives at the root itself. The result isa recurrence relation for the deviations of the trial solutionsi+1 = −2if 00 (x).2f 0 (x)(9.4.6)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).x9.4 Newton-Raphson Method Using Derivative365f 0 (x) ≈f(x + dx) − f(x).dx(9.4.7)This is not, however, a recommended procedure for the following reasons: (i) Youare doing two function evaluationsper step, so at best the superlinear order of√convergence will be only 2. (ii) If you take dx too small you will be wipedout by roundoff, while if you take it too large your order of convergence will beonly linear, no better than using the initial evaluation f 0 (x0 ) for all subsequentsteps.
Therefore, Newton-Raphson with numerical derivatives is (in one dimension)always dominated by the secant method of §9.2. (In multidimensions, where thereis a paucity of available methods, Newton-Raphson with numerical derivatives mustbe taken more seriously. See §§9.6–9.7.)The following function calls a user supplied function funcd(x,fn,df) whichsupplies the function value as fn and the derivative as df. We have includedinput bounds on the root simply to be consistent with previous root-finding routines:Newton does not adjust bounds, and works only on local information at the pointx. The bounds are used only to pick the midpoint as the first guess, and to rejectthe solution if it wanders outside of the bounds.#include <math.h>#define JMAX 20Set to maximum number of iterations.float rtnewt(void (*funcd)(float, float *, float *), float x1, float x2,float xacc)Using the Newton-Raphson method, find the root of a function known to lie in the interval[x1, x2].
The root rtnewt will be refined until its accuracy is known within ±xacc. funcdis a user-supplied routine that returns both the function value and the first derivative of thefunction at the point x.{void nrerror(char error_text[]);int j;float df,dx,f,rtn;rtn=0.5*(x1+x2);Initial guess.for (j=1;j<=JMAX;j++) {(*funcd)(rtn,&f,&df);dx=f/df;rtn -= dx;if ((x1-rtn)*(rtn-x2) < 0.0)nrerror("Jumped out of brackets in rtnewt");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).Equation (9.4.6) says that Newton-Raphson converges quadratically (cf. equation 9.2.3). Near a root, the number of significant digits approximately doubleswith each step.
This very strong convergence property makes Newton-Raphson themethod of choice for any function whose derivative can be evaluated efficiently, andwhose derivative is continuous and nonzero in the neighborhood of a root.Even where Newton-Raphson is rejected for the early stages of convergence(because of its poor global convergence properties), it is very common to “polishup” a root with one or two steps of Newton-Raphson, which can multiply by twoor four its number of significant figures!For an efficient realization of Newton-Raphson the user provides a routine thatevaluates both f(x) and its first derivative f 0 (x) at the point x. The Newton-Raphsonformula can also be applied using a numerical difference to approximate the truelocal derivative,366Chapter 9.Root Finding and Nonlinear Sets of Equationsif (fabs(dx) < xacc) return rtn;Convergence.}nrerror("Maximum number of iterations exceeded in rtnewt");return 0.0;Never get here.}#include <math.h>#define MAXIT 100Maximum allowed number of iterations.float rtsafe(void (*funcd)(float, float *, float *), float x1, float x2,float xacc)Using a combination of Newton-Raphson and bisection, find the root of a function bracketedbetween x1 and x2.
The root, returned as the function value rtsafe, will be refined untilits accuracy is known within ±xacc. funcd is a user-supplied routine that returns both thefunction value and the first derivative of the function.{void nrerror(char error_text[]);int j;float df,dx,dxold,f,fh,fl;float temp,xh,xl,rts;(*funcd)(x1,&fl,&df);(*funcd)(x2,&fh,&df);if ((fl > 0.0 && fh > 0.0) || (fl < 0.0 && fh < 0.0))nrerror("Root must be bracketed in rtsafe");if (fl == 0.0) return x1;if (fh == 0.0) return x2;if (fl < 0.0) {Orient the search so that f (xl) < 0.xl=x1;xh=x2;} else {xh=x1;xl=x2;}rts=0.5*(x1+x2);Initialize the guess for root,dxold=fabs(x2-x1);the “stepsize before last,”dx=dxold;and the last step.(*funcd)(rts,&f,&df);for (j=1;j<=MAXIT;j++) {Loop over allowed iterations.if ((((rts-xh)*df-f)*((rts-xl)*df-f) > 0.0)Bisect if Newton out of range,|| (fabs(2.0*f) > fabs(dxold*df))) {or not decreasing fast enough.dxold=dx;dx=0.5*(xh-xl);rts=xl+dx;if (xl == rts) return rts;Change in root is negligible.} else {Newton step acceptable.
Take it.dxold=dx;dx=f/df;temp=rts;rts -= dx;if (temp == rts) return rts;}if (fabs(dx) < xacc) return rts;Convergence criterion.(*funcd)(rts,&f,&df);The one new function evaluation per iteration.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-файл и есть ли нужная программа для его просмотра.















