Logo ROOT   6.21/01
Reference Guide
GSLRootFinder.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Author: L. Moneta, A. Zsenei 08/2005
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License *
10  * as published by the Free Software Foundation; either version 2 *
11  * of the License, or (at your option) any later version. *
12  * *
13  * This library 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 GNU *
16  * General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library (see file COPYING); if not, write *
20  * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21  * 330, Boston, MA 02111-1307 USA, or contact the author. *
22  * *
23  **********************************************************************/
24 
25 // Header file for class GSLRootFinder
26 //
27 // Created by: moneta at Sun Nov 14 11:27:11 2004
28 //
29 // Last update: Sun Nov 14 11:27:11 2004
30 //
31 #ifndef ROOT_Math_GSLRootFinder
32 #define ROOT_Math_GSLRootFinder
33 
34 
36 
37 #include "Math/IFunctionfwd.h"
38 
39 #include "Math/IRootFinderMethod.h"
40 
41 #include <iostream>
42 
43 namespace ROOT {
44 namespace Math {
45 
46 
47  class GSLRootFSolver;
48  class GSLFunctionWrapper;
49 
50 
51 //________________________________________________________________________________________________________
52  /**
53  Base class for GSL Root-Finding algorithms for one dimensional functions which do not use function derivatives.
54  For finding the roots users should not use this class directly but instantiate the derived classes,
55  for example ROOT::Math::Roots::Brent for using the Brent algorithm.
56  All the classes defining the alhorithms are defined in the header Math/RootFinderAlgorithm.h
57  They possible types implementing root bracketing algorithms which they do not require function
58  derivatives are:
59  <ul>
60  <li>ROOT::Math::Roots::Bisection
61  <li>ROOT::Math::Roots::FalsePos
62  <li>ROOT::Math::Roots::Brent
63  </ul>
64 
65  See also the specific classes for the documentation.
66  See the GSL <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Root-Bracketing-Algorithms.html"> online manual</A> for
67  information on the GSL Root-Finding algorithms
68 
69  @ingroup RootFinders
70  */
71 
72 
74 
75  public:
76  GSLRootFinder();
77  virtual ~GSLRootFinder();
78 
79  private:
80  // usually copying is non trivial, so we make this unaccessible
83 
84  public:
85 
86 
87 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
88  bool SetFunction( const IGradFunction & , double ) {
89  std::cerr <<"GSLRootFinder - Error : this method must be used with a Root Finder algorithm using derivatives" << std::endl;
90  return false;
91  }
92 #endif
93 
94  bool SetFunction( const IGenFunction & f, double xlow, double xup);
95 
96  typedef double ( * GSLFuncPointer ) ( double, void *);
97  bool SetFunction( GSLFuncPointer f, void * params, double xlow, double xup);
98 
100 
101  // iterate to find ROOTS return GSL_CONTINUE if iteration was successful or another error
102  int Iterate();
103 
104  double Root() const;
105 
106  //double XLower() const;
107 
108  //double XUpper() const;
109 
110  /// Find the root
111  bool Solve( int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10);
112 
113  /// Return number of iterations
114  int Iterations() const {
115  return fIter;
116  }
117 
118  /// Return the status of last root finding
119  int Status() const { return fStatus; }
120 
121  const char * Name() const;
122 
123 
124  protected:
125 
126 
127  void SetSolver ( GSLRootFSolver * s );
128 
129  void FreeSolver();
130 
131  private:
132 
135 
136  double fRoot;
137  double fXlow;
138  double fXup;
139  int fIter;
140  int fStatus;
142 
143  };
144 
145 } // namespace Math
146 } // namespace ROOT
147 
148 
149 #endif /* ROOT_Math_GSLRootFinder */
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
int Iterations() const
Return number of iterations.
Returns the available number of logical cores.
Definition: StringConv.hxx:21
const char * Name() const
double GSLRootFinder::XLower() const { return fXlow; }
Root-Finder implementation class using GSL.
GSLRootFinder & operator=(const GSLRootFinder &)
Base class for GSL Root-Finding algorithms for one dimensional functions which do not use function de...
Definition: GSLRootFinder.h:73
#define f(i)
Definition: RSha256.hxx:104
Interface (abstract class) for one-dimensional functions providing a gradient calculation.
Definition: IFunction.h:381
double(* GSLFuncPointer)(double, void *)
Definition: GSLRootFinder.h:96
Interface for finding function roots of one-dimensional functions.
bool Solve(int maxIter=100, double absTol=1E-8, double relTol=1E-10)
Find the root.
static constexpr double s
int Iterate()
This method is implemented only by the GSLRootFinder and GSLRootFinderDeriv classes and will return a...
GSLFunctionWrapper * fFunction
constexpr Double_t E()
Base of natural log: .
Definition: TMath.h:97
double Root() const
Returns the previously calculated root.
virtual bool SetFunction(const ROOT::Math::IGradFunction &, double)
Sets the function for algorithms using derivatives.
Namespace for new Math classes and functions.
void SetSolver(GSLRootFSolver *s)
Wrapper class to the gsl_function C structure.
int Status() const
Return the status of last root finding.
bool SetFunction(const IGenFunction &f, double xlow, double xup)
Sets the function for the rest of the algorithms.