Logo ROOT  
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 */
ROOT::Math::GSLRootFinderDeriv::GSLFdFPointer
void(* GSLFdFPointer)(double, void *, double *, double *)
Definition: GSLRootFinderDeriv.h:103
ROOT::Math::GSLRootFinderDeriv::fStatus
int fStatus
Definition: GSLRootFinderDeriv.h:140
ROOT::Math::GSLRootFinderDeriv::fPrevRoot
double fPrevRoot
Definition: GSLRootFinderDeriv.h:138
ROOT::Math::GSLRootFinderDeriv::fValidPoint
bool fValidPoint
Definition: GSLRootFinderDeriv.h:141
GSLFunctionAdapter.h
IFunction.h
f
#define f(i)
Definition: RSha256.hxx:104
ROOT::Math::GSLRootFinderDeriv::fIter
int fIter
Definition: GSLRootFinderDeriv.h:139
ROOT::Math::GSLRootFinderDeriv::Name
const char * Name() const
Return name of root finder algorithm.
Definition: GSLRootFinderDeriv.cxx:132
ROOT::Math::GSLRootFinderDeriv::SetFunction
virtual bool SetFunction(const ROOT::Math::IGradFunction &, double)
Sets the function for algorithms using derivatives.
Definition: IRootFinderMethod.h:45
ROOT::Math::GSLRootFinderDeriv::fRoot
double fRoot
Definition: GSLRootFinderDeriv.h:137
IFunctionfwd.h
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
IRootFinderMethod.h
ROOT::Math::GSLRootFinderDeriv::fS
GSLRootFdFSolver * fS
Definition: GSLRootFinderDeriv.h:135
ROOT::Math::GSLRootFinderDeriv::~GSLRootFinderDeriv
virtual ~GSLRootFinderDeriv()
Definition: GSLRootFinderDeriv.cxx:58
ROOT::Math::GSLRootFinderDeriv::Iterate
int Iterate()
iterate (return GSL_SUCCESS in case of successful iteration)
Definition: GSLRootFinderDeriv.cxx:107
ROOT::Math::IRootFinderMethod
Interface for finding function roots of one-dimensional functions.
Definition: IRootFinderMethod.h:34
ROOT::Math::IGradientFunctionOneDim
Interface (abstract class) for one-dimensional functions providing a gradient calculation.
Definition: IFunction.h:383
ROOT::Math::GSLFunctionDerivWrapper
class to wrap a gsl_function_fdf (with derivatives)
Definition: GSLFunctionWrapper.h:105
ROOT::Math::GSLRootFinderDeriv::Iterations
int Iterations() const
Return number of iterations.
Definition: GSLRootFinderDeriv.h:117
ROOT::Math::GSLRootFinderDeriv::Status
int Status() const
Return the status of last root finding.
Definition: GSLRootFinderDeriv.h:122
double
double
Definition: Converters.cxx:921
ROOT::Math::GSLRootFinderDeriv::Solve
bool Solve(int maxIter=100, double absTol=1E-8, double relTol=1E-10)
Find the root (return false if failed)
Definition: GSLRootFinderDeriv.cxx:137
void
typedef void((*Func_t)())
ROOT::Math::GSLRootFinderDeriv::GSLFuncPointer
double(* GSLFuncPointer)(double, void *)
Definition: GSLRootFinderDeriv.h:102
ROOT::Math::IBaseFunctionOneDim
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
ROOT::Math::GSLRootFinderDeriv::FreeSolver
void FreeSolver()
Definition: GSLRootFinderDeriv.cxx:102
ROOT::Math::IRootFinderMethod::SetFunction
virtual bool SetFunction(const ROOT::Math::IGradFunction &, double)
Sets the function for algorithms using derivatives.
Definition: IRootFinderMethod.h:45
ROOT::Math::GSLRootFinderDeriv::GSLRootFinderDeriv
GSLRootFinderDeriv()
Definition: GSLRootFinderDeriv.cxx:48
ROOT::Math::GSLRootFinderDeriv::SetFunction
bool SetFunction(const IGradFunction &f, double xstart)
Sets the function for algorithms using derivatives.
Definition: GSLRootFinderDeriv.h:96
ROOT::Math::GSLRootFinderDeriv::Root
double Root() const
Returns the previously calculated root.
Definition: GSLRootFinderDeriv.cxx:127
ROOT::Math::GSLRootFinderDeriv::fFunction
GSLFunctionDerivWrapper * fFunction
Definition: GSLRootFinderDeriv.h:134
ROOT::Math::GSLRootFinderDeriv
Base class for GSL Root-Finding algorithms for one dimensional functions which use function derivativ...
Definition: GSLRootFinderDeriv.h:74
ROOT::Math::GSLRootFinderDeriv::SetSolver
void SetSolver(GSLRootFdFSolver *s)
Definition: GSLRootFinderDeriv.cxx:97
ROOT::Math::GSLRootFinderDeriv::operator=
GSLRootFinderDeriv & operator=(const GSLRootFinderDeriv &)
Definition: GSLRootFinderDeriv.cxx:68
ROOT::Math::GSLFunctionAdapter
Class for adapting any C++ functor class to C function pointers used by GSL.
Definition: GSLFunctionAdapter.h:63
ROOT
VSD Structures.
Definition: StringConv.hxx:21
TMath::E
constexpr Double_t E()
Base of natural log:
Definition: TMath.h:96
ROOT::Math::GSLRootFdFSolver
Root-Finder with derivatives implementation class using GSL.
Definition: GSLRootFdFSolver.h:47
Math
Namespace for new Math classes and functions.