template struct F1dim { const VecDoub &p; const VecDoub ξ Int n; T &func; VecDoub xt; F1dim(VecDoub_I &pp, VecDoub_I &xii, T &funcc) : p(pp), xi(xii), n(pp.size()), func(funcc), xt(n) {} Doub operator() (const Doub x) { for (Int j=0;j struct Linemethod { VecDoub p; VecDoub xi; T &func; Int n; Linemethod(T &funcc) : func(funcc) {} Doub linmin() { Doub ax,xx,xmin; n=p.size(); F1dim f1dim(p,xi,func); ax=0.0; xx=1.0; Brent brent; brent.bracket(ax,xx,f1dim); xmin=brent.minimize(f1dim); for (Int j=0;j struct Df1dim { const VecDoub &p; const VecDoub ξ Int n; T &funcd; VecDoub xt; VecDoub dft; Df1dim(VecDoub_I &pp, VecDoub_I &xii, T &funcdd) : p(pp), xi(xii), n(pp.size()), funcd(funcdd), xt(n), dft(n) {} Doub operator()(const Doub x) { for (Int j=0;j struct Dlinemethod { VecDoub p; VecDoub xi; T &func; Int n; Dlinemethod(T &funcc) : func(funcc) {} Doub linmin() { Doub ax,xx,xmin; n=p.size(); Df1dim df1dim(p,xi,func); ax=0.0; xx=1.0; Dbrent dbrent; dbrent.bracket(ax,xx,df1dim); xmin=dbrent.minimize(df1dim); for (Int j=0;j struct Powell : Linemethod { Int iter; Doub fret; using Linemethod::func; using Linemethod::linmin; using Linemethod::p; using Linemethod::xi; const Doub ftol; Powell(T &func, const Doub ftoll=3.0e-8) : Linemethod(func), ftol(ftoll) {} VecDoub minimize(VecDoub_I &pp) { Int n=pp.size(); MatDoub ximat(n,n,0.0); for (Int i=0;i del) { del=fptt-fret; ibig=i+1; } } if (2.0*(fp-fret) <= ftol*(abs(fp)+abs(fret))+TINY) { return p; } if (iter == ITMAX) throw("powell exceeding maximum iterations."); for (Int j=0;j struct Frprmn : Linemethod { Int iter; Doub fret; using Linemethod::func; using Linemethod::linmin; using Linemethod::p; using Linemethod::xi; const Doub ftol; Frprmn(T &funcd, const Doub ftoll=3.0e-8) : Linemethod(funcd), ftol(ftoll) {} VecDoub minimize(VecDoub_I &pp) { const Int ITMAX=200; const Doub EPS=1.0e-18; const Doub GTOL=1.0e-8; Doub gg,dgg; Int n=pp.size(); p=pp; VecDoub g(n),h(n); xi.resize(n); Doub fp=func(p); func.df(p,xi); for (Int j=0;j test) test=temp; } if (test < GTOL) return p; dgg=gg=0.0; for (Int j=0;j