1 #ifndef theplu_yat_utility_root_finder_derivative_ 2 #define theplu_yat_utility_root_finder_derivative_ 25 #include "Exception.h" 26 #include "univariable/f.h" 27 #include "univariable/df.h" 29 #include <gsl/gsl_errno.h> 30 #include <gsl/gsl_roots.h> 59 unsigned int epochs(
void)
const;
64 const char*
name(
void)
const;
72 virtual bool operator()(
const gsl_root_fdfsolver*)=0;
84 Delta(
double epsabs,
double epsrel);
94 std::unique_ptr<double> prev_;
108 : func_(func), epsabs_(epsabs)
130 double operator()(FUNC& func,
double guess, Stopper&& stopper);
136 double operator()(FUNC& func,
double guess, Stopper&& stopper,
137 unsigned int max_epochs);
147 const gsl_root_fdfsolver_type* type_;
152 std::unique_ptr<gsl_root_fdfsolver, GslFree> solver_;
153 unsigned int epochs_;
164 return (*
this)(func, guess, std::move(stopper), max_epochs);
172 unsigned int max_epochs)
174 gsl_function_fdf gsl_func;
175 gsl_func.f = univariable::f<FUNC>;
176 gsl_func.df = univariable::df<FUNC>;
177 gsl_func.fdf = univariable::fdf<FUNC>;
178 gsl_func.params = &func;
179 gsl_root_fdfsolver_set(solver_.get(), &gsl_func, guess);
181 for (epochs_=0; epochs_<max_epochs && !stopper(solver_.get()); ++epochs_) {
182 int status = gsl_root_fdfsolver_iterate(solver_.get());
184 std::ostringstream ss;
185 ss <<
"RootFinderDerivative: at x = " 186 << gsl_root_fdfsolver_root(solver_.get());
192 return gsl_root_fdfsolver_root(solver_.get());
200 double x = gsl_root_fdfsolver_root(s);
202 return gsl_root_test_residual(f, epsabs_) == GSL_SUCCESS;
Definition: RootFinderDerivative.h:77
Residual(const FUNC &func, double epsabs)
Definition: RootFinderDerivative.h:107
Definition: RootFinderDerivative.h:47
Definition: RootFinderDerivative.h:100
RootFinderDerivative & operator=(const RootFinderDerivative &)=delete
Assignment is not allowed.
Class for errors reported from underlying GSL calls.
Definition: Exception.h:102
The Department of Theoretical Physics namespace as we define it.
Delta(double epsabs, double epsrel)
unsigned int epochs(void) const
Number of epochs (iterations) used in last minimisation.
double operator()(FUNC &func, double guess, Stopper &&stopper)
Definition: RootFinderDerivative.h:160
T max(const T &a, const T &b, const T &c)
Definition: stl_utility.h:699
RootFinderDerivative(const RootFinderDerivative &)=delete
Copy is not allowed.
virtual bool operator()(const gsl_root_fdfsolver *)=0
return true is search should stop
bool operator()(const gsl_root_fdfsolver *)
Definition: RootFinderDerivative.h:198
Definition: RootFinderDerivative.h:68
const char * name(void) const
bool operator()(const gsl_root_fdfsolver *)