ROOT  6.06/09
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 
35 #ifndef ROOT_Math_GSLFunctionAdapter
37 #endif
38 
39 #ifndef ROOT_Math_IFunctionfwd
40 #include "Math/IFunctionfwd.h"
41 #endif
42 
43 #ifndef ROOT_Math_IRootFinderMethod
44 #include "Math/IRootFinderMethod.h"
45 #endif
46 
47 #include <iostream>
48 
49 namespace ROOT {
50 namespace Math {
51 
52 
53  class GSLRootFSolver;
54  class GSLFunctionWrapper;
55 
56 
57 //________________________________________________________________________________________________________
58  /**
59  Base class for GSL Root-Finding algorithms for one dimensional functions which do not use function derivatives.
60  For finding the roots users should not use this class directly but instantiate the derived classes,
61  for example ROOT::Math::Roots::Brent for using the Brent algorithm.
62  All the classes defining the alhorithms are defined in the header Math/RootFinderAlgorithm.h
63  They possible types implementing root bracketing algorithms which they do not require function
64  derivatives are:
65  <ul>
66  <li>ROOT::Math::Roots::Bisection
67  <li>ROOT::Math::Roots::FalsePos
68  <li>ROOT::Math::Roots::Brent
69  </ul>
70 
71  See also the specific classes for the documentation.
72  See the GSL <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Root-Bracketing-Algorithms.html"> online manual</A> for
73  information on the GSL Root-Finding algorithms
74 
75  @ingroup RootFinders
76  */
77 
78 
80 
81  public:
82  GSLRootFinder();
83  virtual ~GSLRootFinder();
84 
85  private:
86  // usually copying is non trivial, so we make this unaccessible
89 
90  public:
91 
92 
93 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
94  bool SetFunction( const IGradFunction & , double ) {
95  std::cerr <<"GSLRootFinder - Error : this method must be used with a Root Finder algorithm using derivatives" << std::endl;
96  return false;
97  }
98 #endif
99 
100  bool SetFunction( const IGenFunction & f, double xlow, double xup);
101 
102  typedef double ( * GSLFuncPointer ) ( double, void *);
103  bool SetFunction( GSLFuncPointer f, void * params, double xlow, double xup);
104 
106 
107  // iterate to find ROOTS return GSL_CONTINUE if iteration was successful or another error
108  int Iterate();
109 
110  double Root() const;
111 
112  //double XLower() const;
113 
114  //double XUpper() const;
115 
116  /// Find the root
117  bool Solve( int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10);
118 
119  /// Return number of iterations
120  int Iterations() const {
121  return fIter;
122  }
123 
124  /// Return the status of last root finding
125  int Status() const { return fStatus; }
126 
127  const char * Name() const;
128 
129 
130  protected:
131 
132 
133  void SetSolver ( GSLRootFSolver * s );
134 
135  void FreeSolver();
136 
137  private:
138 
141 
142  double fRoot;
143  double fXlow;
144  double fXup;
145  int fIter;
146  int fStatus;
148 
149  };
150 
151 } // namespace Math
152 } // namespace ROOT
153 
154 
155 #endif /* ROOT_Math_GSLRootFinder */
int Iterations() const
Return number of iterations.
double Root() const
Returns the previously calculated root.
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:133
const double absTol
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
int Status() const
Return the status of last root finding.
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:79
const char * Name() const
double GSLRootFinder::XLower() const { return fXlow; }
Interface (abstract class) for one-dimensional functions providing a gradient calculation.
Definition: IFunction.h:382
double(* GSLFuncPointer)(double, void *)
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.
int Iterate()
This method is implemented only by the GSLRootFinder and GSLRootFinderDeriv classes and will return a...
GSLFunctionWrapper * fFunction
Double_t E()
Definition: TMath.h:54
double f(double x)
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.
bool SetFunction(const IGenFunction &f, double xlow, double xup)
Sets the function for the rest of the algorithms.