30double get_minima(
const std::function<
double(
double)> &f, 
double lim_a,
 
   34    double prev_mean, mean = std::numeric_limits<double>::infinity();
 
   37    const double M_GOLDEN_RATIO = (1.f + std::sqrt(5.f)) / 2.f;
 
   41        std::swap(lim_a, lim_b);
 
   42    } 
else if (std::abs(lim_a - lim_b) <= EPSILON) {
 
   43        std::cerr << 
"Search range must be greater than " << EPSILON << 
"\n";
 
   51        double ratio = (lim_b - lim_a) / M_GOLDEN_RATIO;
 
   63        mean = (lim_a + lim_b) / 2.f;
 
   67    } 
while (std::abs(lim_a - lim_b) > EPSILON);
 
   69    std::cout << 
" (iters: " << iters << 
") ";
 
 
double get_minima(const std::function< double(double)> &f, double lim_a, double lim_b)
Get the minima of a function in the given interval. To get the maxima, simply negate the function....