正在加载图片...
10.5 Direction Set(Powell's)Methods in Multidimensions 419 normally be a significant addition to the overall computational burden,but we cannot disguise its inelegance. #include "nrutil.h" #define TOL 2.0e-4 Tolerance passed to brent int ncom; Global variables communicate with f1dim float *pcom,*xicom,(*nrfunc)(float []) void linmin(float p[],float xi[],int n,float *fret,float (*func)(float []) Given an n-dimensional point p[1..n]and an n-dimensional direction xi[1..n],moves and http://www.nr. resets p to where the function func(p)takes on a minimum along the direction xi from p, and replaces xi by the actual vector displacement that p was moved.Also returns as fret the value of func at the returned location p.This is actually all accomplished by calling the 83g routines mnbrak and brent. 19881992 float brent(float ax,float bx,float cx, 1600 (including this one) float (*f)(float),float tol,float *xmin); float fidim(float x); 872 void mnbrak(float *ax,float *bx,float *cx,float *fa,float *fb, float *fc,float (*func)(float)); tusers to make one paper from NUMERICAL RECIPES IN int j; float xx,xmin,fx,fb,fa,bx,ax; ncom=n; Define the global variables 7423 (North America to any server computer,is strictly prohibited. by Cambridge University Press.Programs Copyright(C)1988-1992 by Numerical Recipes THE pcom=vector(1,n); xicom=vector(1,n); nrfunc=func; for (i=1;i<=n;i++){ pcom[i]=p[j]; xicom[i]-xi[i]; ax=0.0; Initial guess for brackets. xx=1.0; mnbrak(&ax,&xx,&bx,&fa,&fx,&fb,fidim); 车fretsbrent(a置.xX.bx.f1d5m.T0L,2m1n】 for(j=1;j<=n;j++){ Construct the vector results to return. xi[j]*xmin; p[j]+xi[j]; 2 free_vector(xicom,1,n); free_vector(pcom,1,n); only),orsend email to directcustserv@cambridge.org personal use.Further reproduction,or ART OF SCIENTIFIC COMPUTING(ISBN 0-521-43108-5) #include "nrutil.h" extern int ncom; Defined in linmin Software. extern float *pcom,*xicom,(*nrfunc)(float []) float fidim(float x) (outside North America) Must accompany linmin int j; float f,*xt; xt-vector(1,ncom); for (j=1;j<=ncom;j++)xt[j]=pcom[j]+x*xicom[j]; f=(*nrfunc)(xt); free_vector(xt,1,ncom); return f;10.5 Direction Set (Powell’s) Methods in Multidimensions 419 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). normally be a significant addition to the overall computational burden, but we cannot disguise its inelegance. #include "nrutil.h" #define TOL 2.0e-4 Tolerance passed to brent. int ncom; Global variables communicate with f1dim. float *pcom,*xicom,(*nrfunc)(float []); void linmin(float p[], float xi[], int n, float *fret, float (*func)(float [])) Given an n-dimensional point p[1..n] and an n-dimensional direction xi[1..n], moves and resets p to where the function func(p) takes on a minimum along the direction xi from p, and replaces xi by the actual vector displacement that p was moved. Also returns as fret the value of func at the returned location p. This is actually all accomplished by calling the routines mnbrak and brent. { float brent(float ax, float bx, float cx, float (*f)(float), float tol, float *xmin); float f1dim(float x); void mnbrak(float *ax, float *bx, float *cx, float *fa, float *fb, float *fc, float (*func)(float)); int j; float xx,xmin,fx,fb,fa,bx,ax; ncom=n; Define the global variables. pcom=vector(1,n); xicom=vector(1,n); nrfunc=func; for (j=1;j<=n;j++) { pcom[j]=p[j]; xicom[j]=xi[j]; } ax=0.0; Initial guess for brackets. xx=1.0; mnbrak(&ax,&xx,&bx,&fa,&fx,&fb,f1dim); *fret=brent(ax,xx,bx,f1dim,TOL,&xmin); for (j=1;j<=n;j++) { Construct the vector results to return. xi[j] *= xmin; p[j] += xi[j]; } free_vector(xicom,1,n); free_vector(pcom,1,n); } #include "nrutil.h" extern int ncom; Defined in linmin. extern float *pcom,*xicom,(*nrfunc)(float []); float f1dim(float x) Must accompany linmin. { int j; float f,*xt; xt=vector(1,ncom); for (j=1;j<=ncom;j++) xt[j]=pcom[j]+x*xicom[j]; f=(*nrfunc)(xt); free_vector(xt,1,ncom); return f; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有