Logo ROOT   6.07/09
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 
35 #ifndef ROOT_Math_GSLFunctionAdapter
37 #endif
38 
39 #ifndef ROOT_Math_IFunctionfwd
40 #include "Math/IFunctionfwd.h"
41 #endif
42 #ifndef ROOT_Math_IFunction
43 #include "Math/IFunction.h"
44 #endif
45 
46 #ifndef ROOT_Math_IRootFinderMethod
47 #include "Math/IRootFinderMethod.h"
48 #endif
49 
50 #include <iostream>
51 
52 namespace ROOT {
53 namespace Math {
54 
55 
56  class GSLRootFdFSolver;
57  class GSLFunctionDerivWrapper;
58 
59 
60 //_____________________________________________________________________________________
61  /**
62  Base class for GSL Root-Finding algorithms for one dimensional functions which use function derivatives.
63  For finding the roots users should not use this class directly but instantiate the derived classes,
64  for example ROOT::Math::Roots::Newton for using the Newton algorithm.
65  All the classes defining the alhorithms are defined in the header Math/RootFinderAlgorithm.h
66  They possible types implementing root bracketing algorithms which use function
67  derivatives are:
68  <ul>
69  <li>ROOT::Math::Roots::Newton
70  <li>ROOT::Math::Roots::Secant
71  <li>ROOT::Math::Roots::Steffenson
72  </ul>
73 
74  See also those classes for the documentation.
75  See the GSL <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Root-Finding-Algorithms-using-Derivatives.html"> online manual</A> for
76  information on the GSL Root-Finding algorithms
77 
78  @ingroup RootFinders
79  */
80 
81 
83 
84 public:
86  virtual ~GSLRootFinderDeriv();
87 
88 private:
89  // usually copying is non trivial, so we make this unaccessible
92 
93 public:
94 
95 
96 
97 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
98  bool SetFunction( const IGenFunction & , double , double ) {
99  std::cerr <<"GSLRootFinderDeriv - Error : Algorithm requirs derivatives" << std::endl;
100  return false;
101  }
102 #endif
103 
104  bool SetFunction( const IGradFunction & f, double xstart) {
105  const void * p = &f;
107  }
108 
109 
110  typedef double ( * GSLFuncPointer ) ( double, void *);
111  typedef void ( * GSLFdFPointer ) ( double, void *, double *, double *);
112  bool SetFunction( GSLFuncPointer f, GSLFuncPointer df, GSLFdFPointer fdf, void * p, double Root );
113 
115 
116  /// iterate (return GSL_SUCCESS in case of successful iteration)
117  int Iterate();
118 
119  double Root() const;
120 
121  /// Find the root (return false if failed)
122  bool Solve( int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10);
123 
124  /// Return number of iterations
125  int Iterations() const {
126  return fIter;
127  }
128 
129  /// Return the status of last root finding
130  int Status() const { return fStatus; }
131 
132  const char * Name() const;
133 
134 protected:
135 
136  void SetSolver ( GSLRootFdFSolver * s );
137 
138  void FreeSolver();
139 
140 private:
141 
144 
145  mutable double fRoot;
146  mutable double fPrevRoot;
147  int fIter;
148  int fStatus;
150 
151 };
152 
153 } // namespace Math
154 } // namespace ROOT
155 
156 
157 #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:133
const double absTol
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
double Root() const
Returns the previously calculated root.
bool Solve(int maxIter=100, double absTol=1E-8, double relTol=1E-10)
Find the root (return false if failed)
class to wrap a gsl_function_fdf (with derivatives)
Interface (abstract class) for one-dimensional functions providing a gradient calculation.
Definition: IFunction.h:382
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.
Class for adapting any C++ functor class to C function pointers used by GSL.
GSLRootFinderDeriv & operator=(const GSLRootFinderDeriv &)
Double_t E()
Definition: TMath.h:54
Root-Finder with derivatives implementation class using GSL.
double f(double x)
virtual bool SetFunction(const ROOT::Math::IGradFunction &, double)
Sets the function for algorithms using derivatives.
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)())
const char * Name() const
Return name of root finder algorithm.
int Status() const
Return the status of last root finding.
int Iterations() const
Return number of iterations.