正在加载图片...
356 Chapter 9. Root Finding and Nonlinear Sets of Equations f(x) http://www.nr. Permission is read able files .com or call (including this one) granted fori 19881992 11-800-872 134 (North America to any server computer, one paper Cambridge University Press. tusers to make from NUMERICAL RECIPES IN THE Figure 9.2.3.Example where both the secant and false position methods will take many iterations to 是 ART arrive at the true root.This function would be difficult for mamy other root-finding methods. Programs False position,since it sometimes keeps an older rather than newer function evaluation,has a lower order of convergence.Since the newer function value will sometimes be kept,the method is often superlinear,but estimation of its exact order is not so easy. to dir Here are sample implementations of these two related methods.While these methods are standard textbook fare,Ridders'method,described below,or Brent's method.in the next section.are almost always better choices.Figure 9.2.3 shows the 1788-1982 OF SCIENTIFIC COMPUTING(ISBN behavior of secant and false-position methods in a difficult situation. #include <math.h> #define MAXIT 30 Set to the maximum allowed number of iterations. Further reproduction Numerical Recipes 10-621 43108 float rtflsp(float (*func)(float),float x1,float x2,float xacc) Using the false position method,find the root of a function func known to lie between x1 and x2.The root,returned as rtflsp.is refined until its accuracy is +xacc. (outside void nrerror(char error._text[☐); North Software. int j; float fl,fh,xl,xh,swap,dx,del,f,rtf; f1=(*func)(x1); visit website fh=(*func)(x2) Be sure the interval brackets a root. machine if(f1*fh>0.0) nrerror("Root must be bracketed in rtflsp"); 1f(f1<0.0) Identify the limits so that xl corresponds to the low X=X1: side. xh=x2; else x1=x2; xh=x1; swap=fl;356 Chapter 9. Root Finding and Nonlinear Sets of Equations 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 machine￾readable 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). 2 f(x) 134 x Figure 9.2.3. Example where both the secant and false position methods will take many iterations to arrive at the true root. This function would be difficult for many other root-finding methods. False position, since it sometimes keeps an older rather than newer function evaluation, has a lower order of convergence. Since the newer function value will sometimes be kept, the method is often superlinear, but estimation of its exact order is not so easy. Here are sample implementations of these two related methods. While these methods are standard textbook fare, Ridders’ method, described below, or Brent’s method, in the next section, are almost always better choices. Figure 9.2.3 shows the behavior of secant and false-position methods in a difficult situation. #include <math.h> #define MAXIT 30 Set to the maximum allowed number of iterations. float rtflsp(float (*func)(float), float x1, float x2, float xacc) Using the false position method, find the root of a function func known to lie between x1 and x2. The root, returned as rtflsp, is refined until its accuracy is ±xacc. { void nrerror(char error_text[]); int j; float fl,fh,xl,xh,swap,dx,del,f,rtf; fl=(*func)(x1); fh=(*func)(x2); Be sure the interval brackets a root. if (fl*fh > 0.0) nrerror("Root must be bracketed in rtflsp"); if (fl < 0.0) { Identify the limits so that xl corresponds to the low xl=x1; side. xh=x2; } else { xl=x2; xh=x1; swap=fl;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有