#include #include "nr.h" using namespace std; namespace { inline void get_psum(Mat_I_DP &p, Vec_O_DP &psum) { int n,m; DP sum; int mpts=p.nrows(); int ndim=p.ncols(); for (n=0;n yhi) { ihi=0; ilo=1; ynhi=yhi; yhi=ylo; ylo=ynhi; } for (i=3;i<=mpts;i++) { yt=y[i-1]+tt*log(ran1(idum)); if (yt <= ylo) { ilo=i-1; ylo=yt; } if (yt > yhi) { ynhi=yhi; ihi=i-1; yhi=yt; } else if (yt > ynhi) { ynhi=yt; } } rtol=2.0*fabs(yhi-ylo)/(fabs(yhi)+fabs(ylo)); if (rtol < ftol || iter < 0) { SWAP(y[0],y[ilo]); for (n=0;n= ynhi) { ysave=yhi; ytry=amotsa(p,y,psum,pb,yb,funk,ihi,yhi,0.5); if (ytry >= ysave) { for (i=0;i