minimizer1d.hpp
Go to the documentation of this file.
1 #ifndef JULIAN_MINIMIZER1D_HPP
2 #define JULIAN_MINIMIZER1D_HPP
3 
5 #include <gsl/gsl_errno.h>
6 #include <gsl/gsl_math.h>
7 #include <gsl/gsl_min.h>
8 
9 namespace julian {
10 
11 
45  };
46 
65  template<typename F>
66  double minimizer1d(F f, double x_lo, double x_hi, double guess, double precision, int number_of_iterations, Minimizer1d t) {
68  gsl_function *gsl_f = static_cast<gsl_function*>(&pF);
69 
70  const gsl_min_fminimizer_type *T;
71  gsl_min_fminimizer *s;
72  switch (t) {
74  T = gsl_min_fminimizer_goldensection;
75  break;
77  T = gsl_min_fminimizer_brent;
78  break;
80  T = gsl_min_fminimizer_quad_golden;
81  break;
82  }
83 
84  s = gsl_min_fminimizer_alloc (T);
85  gsl_min_fminimizer_set (s, gsl_f, guess, x_lo, x_hi);
86 
87  int status;
88  int iter = 0;
89  do {
90  iter++;
91  status = gsl_min_fminimizer_iterate (s);
92  status = gsl_min_test_interval (x_lo, x_hi, 0.0, precision);
93  } while (status == GSL_CONTINUE && iter < number_of_iterations);
94 
95  double ret = gsl_min_fminimizer_x_minimum (s);
96  gsl_min_fminimizer_free (s);
97 
98  return ret;
99  }
100 } // namespace julian
101 
102 #endif
File contains adapter of GSL Function.
Definition: cadHoliday.cpp:3
Class implements adapter for gsl_function.
Definition: GslFunctionAdapter.hpp:25
Brent-Gill-Murray algorithm.
Minimizer1d
Types of 1d minimizers algorithms.
Definition: minimizer1d.hpp:42
double minimizer1d(F f, double x_lo, double x_hi, double guess, double precision, int number_of_iterations, Minimizer1d t)
Function finds minimum of provided one-argument function.
Definition: minimizer1d.hpp:66