#include #include #include "nr.h" using namespace std; void NR::lnsrch(Vec_I_DP &xold, const DP fold, Vec_I_DP &g, Vec_IO_DP &p, Vec_O_DP &x, DP &f, const DP stpmax, bool &check, DP func(Vec_I_DP &)) { const DP ALF=1.0e-4, TOLX=numeric_limits::epsilon(); int i; DP a,alam,alam2=0.0,alamin,b,disc,f2=0.0; DP rhs1,rhs2,slope,sum,temp,test,tmplam; int n=xold.size(); check=false; sum=0.0; for (i=0;i stpmax) for (i=0;i= 0.0) nrerror("Roundoff problem in lnsrch."); test=0.0; for (i=0;i test) test=temp; } alamin=TOLX/test; alam=1.0; for (;;) { for (i=0;i0.5*alam) tmplam=0.5*alam; } } alam2=alam; f2 = f; alam=MAX(tmplam,0.1*alam); } }