Warning, /include/Herwig/Shower/Dipole/AlphaS/gsl.tcc is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002
0003 // math/gsl.tcc is part of matchbox
0004 // (C) 2008 Simon Platzer -- sp@particle.uni-karlsruhe.de
0005
0006 #include <cassert>
0007
0008 #include "gsl/gsl_errno.h"
0009
0010 namespace matchbox { namespace gsl {
0011
0012 template<class Function>
0013 double function_wrapper (double x, void * fptr) {
0014 return (*reinterpret_cast<Function *>(fptr)).operator () (x);
0015 }
0016
0017 /// given a unary function, return an appropriate
0018 /// gsl function object
0019 template<class Function>
0020 gsl_function make_function (Function& f) {
0021 gsl_function conv;
0022 conv.function = &function_wrapper<Function>;
0023 conv.params = &f;
0024 return conv;
0025 }
0026
0027 template<class Function, unsigned long MaxIterations>
0028 double bisection_root_solver<Function,MaxIterations>::solve (std::pair<double,double> interval, double precision) {
0029
0030 assert(interval.first < interval.second);
0031
0032 gsl_function F = make_function(f);
0033
0034 gsl_root_fsolver_set (s, &F, interval.first, interval.second);
0035
0036 unsigned long iterations = 0;
0037 double sol;
0038 int status;
0039
0040 do {
0041 ++iterations;
0042 status = gsl_root_fsolver_iterate (s);
0043 sol = gsl_root_fsolver_root (s);
0044 interval.first = gsl_root_fsolver_x_lower(s);
0045 interval.second = gsl_root_fsolver_x_upper(s);
0046 status = gsl_root_test_interval (interval.first,interval.second,0,precision);
0047 } while (status == GSL_CONTINUE && iterations < MaxIterations);
0048
0049 return sol;
0050
0051 }
0052
0053 }}