All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
root_toms748.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2013-2014, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 /** \file root_toms748.h
24  \brief File defining \ref o2scl::root_toms748
25 */
26 #ifndef O2SCL_ROOT_TOMS748_H
27 #define O2SCL_ROOT_TOMS748_H
28 
29 #include <string>
30 
31 #include <boost/math/tools/roots.hpp>
32 
33 #include <o2scl/root.h>
34 
35 namespace o2scl {
36 
37  /** \brief Wrapper for Boost 1-d solver
38  */
39  template<class func_t=funct11> class root_toms748 :
40  public root_bkt<func_t> {
41 
42  public:
43 
44  root_toms748() {
45  }
46 
47  virtual ~root_toms748() {}
48 
49  /// Return the type, \c "root_toms748".
50  virtual const char *type() { return "root_toms748"; }
51 
52  /// Solve \c func using \c x as an initial guess, returning \c x.
53  virtual int solve_bkt(double &x1, double x2, func_t &func) {
54  std::pair<double,double> res;
55  size_t digits;
56  if (this->tol_rel>1.0) digits=1;
57  else if (this->tol_rel<=0.0) digits=18;
58  else digits=((size_t)(-log10(this->tol_rel)));
59  boost::math::tools::eps_tolerance<double> tol(digits);
60  size_t niter=((size_t)this->ntrial);
61  res=boost::math::tools::toms748_solve(func,x1,x2,tol,niter);
62  this->last_ntrial=niter;
63  x1=res.first;
64  return 0;
65  }
66 
67  };
68 
69 }
70 
71 #endif
int ntrial
Maximum number of iterations (default 100)
Definition: root.h:75
One-dimensional bracketing solver [abstract base].
Definition: root.h:144
double tol_rel
The maximum value of the functions for success (default )
Definition: root.h:64
virtual int solve_bkt(double &x1, double x2, func_t &func)
Solve func using x as an initial guess, returning x.
Definition: root_toms748.h:53
virtual const char * type()
Return the type, "root_toms748".
Definition: root_toms748.h:50
int last_ntrial
The number of iterations used in the most recent solve.
Definition: root.h:83
Wrapper for Boost 1-d solver.
Definition: root_toms748.h:39
static const double x2[5]
Definition: inte_qng_gsl.h:66
static const double x1[5]
Definition: inte_qng_gsl.h:48

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).
Hosted at Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads..