1 #ifndef TOON_GOLDEN_SECTION_H
2 #define TOON_GOLDEN_SECTION_H
11 using std::numeric_limits;
26 template<
class Functor,
class Precision>
Vector<2, Precision> golden_section_search(Precision a, Precision b, Precision c, Precision fb,
const Functor& func,
int maxiterations, Precision tol = sqrt(numeric_limits<Precision>::epsilon()))
30 const Precision g = (3.0 - sqrt(5))/2;
32 Precision x1, x2, fx1, fx2;
58 while(
abs(c-a) > tol * (
abs(x2)+
abs(x1)) && itnum < maxiterations)
79 x1= x2 - g * (x2 - a);
88 return makeVector<Precision>(x1, fx1);
90 return makeVector<Precision>(x2, fx2);
105 template<
class Functor,
class Precision>
Vector<2, Precision> golden_section_search(Precision a, Precision b, Precision c,
const Functor& func,
int maxiterations, Precision tol = sqrt(numeric_limits<Precision>::epsilon()))
Everything lives inside this namespace.
Vector< 2, Precision > golden_section_search(Precision a, Precision b, Precision c, Precision fb, const Functor &func, int maxiterations, Precision tol=sqrt(numeric_limits< Precision >::epsilon()))