Logo ROOT   6.12/07
Reference Guide
GSLRootFinderDeriv.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Authors: 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 GSLRootFinderDeriv
26 //
27 // Created by: moneta at Sun Nov 21 16:26:03 2004
28 //
29 // Last update: Sun Nov 21 16:26:03 2004
30 //
31 #ifndef ROOT_Math_GSL_RootFinderDeriv
32 #define ROOT_Math_GSL_RootFinderDeriv
33 
34 
36 
37 #include "Math/IFunctionfwd.h"
38 #include "Math/IFunction.h"
39 
40 #include "Math/IRootFinderMethod.h"
41 
42 #include <iostream>
43 
44 namespace ROOT {
45 namespace Math {
46 
47 
48  class GSLRootFdFSolver;
49  class GSLFunctionDerivWrapper;
50 
51 
52 //_____________________________________________________________________________________
53  /**
54  Base class for GSL Root-Finding algorithms for one dimensional functions which use function derivatives.
55  For finding the roots users should not use this class directly but instantiate the derived classes,
56  for example ROOT::Math::Roots::Newton for using the Newton algorithm.
57  All the classes defining the alhorithms are defined in the header Math/RootFinderAlgorithm.h
58  They possible types implementing root bracketing algorithms which use function
59  derivatives are:
60  <ul>
61  <li>ROOT::Math::Roots::Newton
62  <li>ROOT::Math::Roots::Secant
63  <li>ROOT::Math::Roots::Steffenson
64  </ul>
65 
66  See also those classes for the documentation.
67  See the GSL <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Root-Finding-Algorithms-using-Derivatives.html"> online manual</A> for
68  information on the GSL Root-Finding algorithms
69 
70  @ingroup RootFinders
71  */
72 
73 
75 
76 public:
78  virtual ~GSLRootFinderDeriv();
79 
80 private:
81  // usually copying is non trivial, so we make this unaccessible
84 
85 public:
86 
87 
88 
89 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
90  bool SetFunction( const IGenFunction & , double , double ) {
91  std::cerr <<"GSLRootFinderDeriv - Error : Algorithm requirs derivatives" << std::endl;
92  return false;
93  }
94 #endif
95 
96  bool SetFunction( const IGradFunction & f, double xstart) {
97  const void * p = &f;
99  }
100 
101 
102  typedef double ( * GSLFuncPointer ) ( double, void *);
103  typedef void ( * GSLFdFPointer ) ( double, void *, double *, double *);
104  bool SetFunction( GSLFuncPointer f, GSLFuncPointer df, GSLFdFPointer fdf, void * p, double Root );
105 
107 
108  /// iterate (return GSL_SUCCESS in case of successful iteration)
109  int Iterate();
110 
111  double Root() const;
112 
113  /// Find the root (return false if failed)
114  bool Solve( int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10);
115 
116  /// Return number of iterations
117  int Iterations() const {
118  return fIter;
119  }
120 
121  /// Return the status of last root finding
122  int Status() const { return fStatus; }
123 
124  const char * Name() const;
125 
126 protected:
127 
128  void SetSolver ( GSLRootFdFSolver * s );
129 
130  void FreeSolver();
131 
132 private:
133 
136 
137  mutable double fRoot;
138  mutable double fPrevRoot;
139  int fIter;
140  int fStatus;
142 
143 };
144 
145 } // namespace Math
146 } // namespace ROOT
147 
148 
149 #endif /* ROOT_Math_GSL_RootFinderDeriv */
int Iterate()
iterate (return GSL_SUCCESS in case of successful iteration)
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
int Status() const
Return the status of last root finding.
bool Solve(int maxIter=100, double absTol=1E-8, double relTol=1E-10)
Find the root (return false if failed)
double Root() const
Returns the previously calculated root.
class to wrap a gsl_function_fdf (with derivatives)
Interface (abstract class) for one-dimensional functions providing a gradient calculation.
Definition: IFunction.h:381
GSLFunctionDerivWrapper * fFunction
void SetSolver(GSLRootFdFSolver *s)
Interface for finding function roots of one-dimensional functions.
double(* GSLFuncPointer)(double, void *)
bool SetFunction(const IGradFunction &f, double xstart)
Sets the function for algorithms using derivatives.
const char * Name() const
Return name of root finder algorithm.
Class for adapting any C++ functor class to C function pointers used by GSL.
GSLRootFinderDeriv & operator=(const GSLRootFinderDeriv &)
constexpr Double_t E()
Definition: TMath.h:74
Root-Finder with derivatives implementation class using GSL.
virtual bool SetFunction(const ROOT::Math::IGradFunction &, double)
Sets the function for algorithms using derivatives.
static constexpr double s
Base class for GSL Root-Finding algorithms for one dimensional functions which use function derivativ...
Namespace for new Math classes and functions.
void(* GSLFdFPointer)(double, void *, double *, double *)
typedef void((*Func_t)())
int Iterations() const
Return number of iterations.