正在加载图片...
388 Chapter 9.Root Finding and Nonlinear Sets of Equations if (temp test)test-temp; *check=(test TOLMIN 1 0); FREERETURN test=0.0; Test for convergence on 6x. for(i=1;1<=n;i++)[ temp=(fabs(x [i]-xold[i]))/FMAX(fabs(x[i]),1.0); if (temp test)test=temp; if (test TOLX)FREERETURN http://www.n Permission is read able files nrerror("MAXITS exceeded in newt"); 2 83 granted for #include <math.h> #include "nrutil.h" 11-600 #define EPS 1.0e-4 Approximate square root of the machine precision. void fdjac(int n,float x[,float fvec[],float **df, /Cambridge void(*vecfunc)(int,float☐,f1oat☐)) from NUMERICAL RECIPES IN 19881992 Computes forward-difference approximation to Jacobian.On input,x[1..n]is the point at which the Jacobian is to be evaluated,fvec[1..n]is the vector of function values at the point,and vecfunc(n,x,f)is a user-supplied routine that returns the vector of functions at (Nort server users to make x.On output,df [1..n][1..n]is the Jacobian array. Ameri computer, one paper UnN电.t THE int i,j; ART float h,temp,*f; 是 f=vector(1,n); for (j=1;j<=n;j++) temp=x[j]; h=EPS*fabs(temp); st st Programs 1f(h=0.0)h=EPS: x[j]=temp+h; Trick to reduce finite precision error. h=x[j]-temp; to dir (*vecfunc)(n,x,f); x[j]=temp; rectcustser 18881920 OF SCIENTIFIC COMPUTING(ISBN for (i=1;i<=n;i++)df[i][j]=(f[i]-fvec[i])/h; Forward difference for- mula. free_vector(f,1,n); v@cam 10-621 #include "nrutil.h" idge.org .Further reproduction, Numerical Recipes -43108 extern int nn; extern float *fvec; (outside extern void (*nrfuncv)(int n,float v[],float f[]); Software. float fmin(float x[]) Returns f=F.F at x.The global pointer *nrfuncv points to a routine that returns the Ame vector of functions at x.It is set to point to a user-supplied routine in the calling program. Global variables also communicate the function values back to the calling program. 1nt1: float sum; (*nrfuncv)(nn,x,fvec); for (sum=0.0,i=1;i<=nn;i++)sum +SQR(fvec [i]); return 0.5*sum;388 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). if (temp > test) test=temp; } *check=(test < TOLMIN ? 1 : 0); FREERETURN } test=0.0; Test for convergence on δx. for (i=1;i<=n;i++) { temp=(fabs(x[i]-xold[i]))/FMAX(fabs(x[i]),1.0); if (temp > test) test=temp; } if (test < TOLX) FREERETURN } nrerror("MAXITS exceeded in newt"); } #include <math.h> #include "nrutil.h" #define EPS 1.0e-4 Approximate square root of the machine precision. void fdjac(int n, float x[], float fvec[], float **df, void (*vecfunc)(int, float [], float [])) Computes forward-difference approximation to Jacobian. On input, x[1..n] is the point at which the Jacobian is to be evaluated, fvec[1..n] is the vector of function values at the point, and vecfunc(n,x,f) is a user-supplied routine that returns the vector of functions at x. On output, df[1..n][1..n] is the Jacobian array. { int i,j; float h,temp,*f; f=vector(1,n); for (j=1;j<=n;j++) { temp=x[j]; h=EPS*fabs(temp); if (h == 0.0) h=EPS; x[j]=temp+h; Trick to reduce finite precision error. h=x[j]-temp; (*vecfunc)(n,x,f); x[j]=temp; for (i=1;i<=n;i++) df[i][j]=(f[i]-fvec[i])/h; Forward difference for- } mula. free_vector(f,1,n); } #include "nrutil.h" extern int nn; extern float *fvec; extern void (*nrfuncv)(int n, float v[], float f[]); float fmin(float x[]) Returns f = 1 2 F · F at x. The global pointer *nrfuncv points to a routine that returns the vector of functions at x. It is set to point to a user-supplied routine in the calling program. Global variables also communicate the function values back to the calling program. { int i; float sum; (*nrfuncv)(nn,x,fvec); for (sum=0.0,i=1;i<=nn;i++) sum += SQR(fvec[i]); return 0.5*sum; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有