#include #include #include "nr.h" using namespace std; // Driver for routine amebsa int idum=(-64); DP tfunk(Vec_I_DP &p) { const int N=4; const DP RAD=0.3,AUG=2.0; const DP wid_d[N]={1.0,3.0,10.0,30.0}; int j; DP q,r,sumd=0.0,sumr=0.0; Vec_DP wid(wid_d,N); for (j=0;j= 0 ? int(q+0.5) : -int(0.5-q)); sumr += q*q; sumd += (q-r)*(q-r); } return 1+sumr*(1+(sumd > RAD*RAD ? AUG : AUG*sumd/(RAD*RAD))); } int main(void) { const int NP=4, MP=5; const DP FTOL=1.0e-6; const DP xoff[NP]={10.0,10.0,10.0,10.0}; int i,iiter,iter,j,jiter,nit; DP temptr,yb,ybb; Vec_DP x(NP),y(MP),pb(NP); Mat_DP p(MP,NP); for (i=0;i> temptr >> iiter; if (temptr <= 0.0) break; ybb=1.0e30; nit=0; for (jiter=0;jiter<100;jiter++) { iter=iiter; temptr *= 0.8; NR::amebsa(p,y,pb,yb,FTOL,tfunk,iter,temptr); nit += iiter-iter; if (yb < ybb) { ybb=yb; cout << setw(6) << nit << setw(14) << temptr; for (j=0;j 0) break; } cout << endl << "Vertices of final 3-D simplex and"; cout << " function values at the vertices:" << endl; cout << setw(3) << "i" << setw(10) << "w[i]" << setw(12) << "x[i]"; cout << setw(12) << "y[i]" << setw(12) << "z[i]"; cout << setw(14) << "function" << endl << endl; for (i=0;i