正在加载图片...
412 Chapter 10. Minimization or Maximization of Functions if(11=11o)[ for (j=1;j<=ndim;j++) p[i][j]=psum[j]=0.5*(p[i][j]+p[i1o][j]); y[i]=(*funk)(psum); *nfunk +ndim; Keep track of function evaluations GET_PSUM Recompute psum else --(*nfunk); Correct the evaluation count. Go back for the test of doneness and the next free_vector(psum,1,ndim); iteration granted for #include "nrutil.h" -200 float amotry(float *p,float y[],float psum[],int ndim, float (*funk)(float [])int ihi,float fac) Extrapolates by a factor fac through the face of the simplex across from the high point,tries from NUMERICAL RECIPES I 19881992 it,and replaces the high point if the new point is better. int ji (North University Press. 令 float faci,fac2,ytry,*ptryi ptry=vector(1,ndim); America computer, fac1=(1.0-fac)/ndim; one paper THE ART fac2=faci-fac; for (j=1;j<=ndim;j++)ptry[j]=psum[j]*fac1-p[ihi][j]*fac2; ytry=(*funk)(ptry); Evaluate the function at the trial point. Programs if (ytry y[ihi]){ If it's better than the highest,then replace the highest. ictly proh y[ihi]=ytry; for (j=1;j<=ndim;j++){ psum[j]ptry[j]-p[ihi][j]; p[ihi][i]=ptry[j]; to dir free_vector(ptry,1,ndim); rectcustsen OF SCIENTIFIC COMPUTING(ISBN return ytry; @cambridge.org 1988-1992 by Numerical Recipes 10-:6211 CITED REFERENCES AND FURTHER READING: 43108-5 Nelder,J.A.,and Mead,R.1965,Computer Journal,vol.7,pp.308-313.[1] Yarbro.L.A.,and Deming,S.N.1974,Ana/ytica Chimica Acta,vol.73,pp.391-398. (outside Jacoby,S.L.S,Kowalik,J.S.,and Pizzo,J.T.1972,Iterative Methods for Nonlinear Optimization Software. Problems (Englewood Cliffs,NJ:Prentice-Hall) ying of 10.5 Direction Set (Powell's)Methods in Multidimensions We know (810.1-810.3)how to minimize a function of one variable.If we start at a point P in N-dimensional space,and proceed from there in some vector412 Chapter 10. Minimization or Maximization of Functions 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 (i != ilo) { for (j=1;j<=ndim;j++) p[i][j]=psum[j]=0.5*(p[i][j]+p[ilo][j]); y[i]=(*funk)(psum); } } *nfunk += ndim; Keep track of function evaluations. GET_PSUM Recompute psum. } } else --(*nfunk); Correct the evaluation count. } Go back for the test of doneness and the next free_vector(psum,1,ndim); iteration. } #include "nrutil.h" float amotry(float **p, float y[], float psum[], int ndim, float (*funk)(float []), int ihi, float fac) Extrapolates by a factor fac through the face of the simplex across from the high point, tries it, and replaces the high point if the new point is better. { int j; float fac1,fac2,ytry,*ptry; ptry=vector(1,ndim); fac1=(1.0-fac)/ndim; fac2=fac1-fac; for (j=1;j<=ndim;j++) ptry[j]=psum[j]*fac1-p[ihi][j]*fac2; ytry=(*funk)(ptry); Evaluate the function at the trial point. if (ytry < y[ihi]) { If it’s better than the highest, then replace the highest. y[ihi]=ytry; for (j=1;j<=ndim;j++) { psum[j] += ptry[j]-p[ihi][j]; p[ihi][j]=ptry[j]; } } free_vector(ptry,1,ndim); return ytry; } CITED REFERENCES AND FURTHER READING: Nelder, J.A., and Mead, R. 1965, Computer Journal, vol. 7, pp. 308–313. [1] Yarbro, L.A., and Deming, S.N. 1974, Analytica Chimica Acta, vol. 73, pp. 391–398. Jacoby, S.L.S, Kowalik, J.S., and Pizzo, J.T. 1972, Iterative Methods for Nonlinear Optimization Problems (Englewood Cliffs, NJ: Prentice-Hall). 10.5 Direction Set (Powell’s) Methods in Multidimensions We know (§10.1–§10.3) how to minimize a function of one variable. If we start at a point P in N-dimensional space, and proceed from there in some vector
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有