#include #define NMAX 5000 /* maximum number of function evaluations */ #define ALPHA 1.0 /* various parameters */ #define BETA 0.5 #define GAMMA 2.0 #define GET_PSUM for (j=1; j<=ndim; j++) { for (i=1, sum=0.0; i<=mpts;i++) sum += p[i][j]; psum[j]=sum;} void amoeba(p, y, ndim, ftol, funk, nfunk) float **p, y[], ftol, (*funk)(); int ndim, *nfunk; /* Multidimensional minimization of function funk(x) where x[1..ndim] is a vector in ndim dimensions, by the downhill simplex method of Nelder and Mead. The matrix p[1..ndim+1][1..ndim] is input its ndim+1 rows are ndim-dimensional vectors which are the vertices of the starting simplex. Also input is the vector y[1..ndim+1] whose components must be preinitialized to the values of funk evaluated at the ndim+1 vertices of p. ftol is the fracional convergence tolerance to be achieved in the function value (n.b.!). On output p and y will have been reset to ndim+1 new points all within ftol of the minimum function valueand nfunk gives the number of function evaluations taken. */ { int i,j,ilo,ihi,mpts=ndim+1; float ytry,ysave,sum,rtol, amotry(),*psum,*vector(); void nrerror(), free_vector();