function [V0,y0,dV,dy]=nelder(F,V,min1,max1,epsilon,show) %Input - F is input as an M-file function % - V is a 3xn matrix containing starting simplex % - min1 & max1 are minimum and maximum number of iterations % - epsilon is the tolerance % - show == 1 displays iterations (P and Q) %Output - V0 is the vertex forthe minimum % - y0 is the function value F(V0) % - dV is the size of the final simplex % - dy is the error bound for the minimum % - P is a matrix containing the vertex iterations % - Q is an array containing the iterations for F(P) %Call [V0,y0,dV,dy]=nelder(@F,V,min1,max1,epsilon,show) % NUMERICAL METHODS: Matlab Programs % (c) 2004 by John H. Mathews and Kurtis D. Fink % Complementary Software to accompany the textbook: % NUMERICAL METHODS: Using Matlab, Fourth Edition % ISBN: 0-13-065248-2 % Prentice-Hall Pub. Inc. % One Lake Street % Upper Saddle River, NJ 07458 if nargin==5, show=0; end [mm n]=size(V); % Order the vertices for j=1:n+1 Z=V(j,1:n); Y(j)=F(Z); end [mm lo]=min(Y); [mm hi]=max(Y); li=hi; ho=lo; for j=1:n+1 if(j~=lo&j~=hi&Y(j)<=Y(li)) li=j; end if (j~=hi&j~=lo&Y(j)>=Y(ho)) ho=j; end end cnt=0; % Start of Nelder-Mead algorithm while (Y(hi)>Y(lo)+epsilon&cnt=Y(ho)) ho=j; end end cnt=cnt+1; P(cnt,:)=V(lo,:); Q(cnt)=Y(lo); end % End of Nelder-Mead algorithm %Determine size of simplex snorm=0; for j=1:n+1 s=norm(V(j)-V(lo)); if(s>=snorm) snorm=s; end end Q=Q'; V0=V(lo,1:n); y0=Y(lo); dV=snorm; dy=abs(Y(hi)-Y(lo)); if (show==1) disp([P Q]) end