ROOT logo
// @(#)root/mathmore:$Id$
// Authors: L. Moneta, A. Zsenei   08/2005 

 /**********************************************************************
  *                                                                    *
  * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
  *                                                                    *
  * This library is free software; you can redistribute it and/or      *
  * modify it under the terms of the GNU General Public License        *
  * as published by the Free Software Foundation; either version 2     *
  * of the License, or (at your option) any later version.             *
  *                                                                    *
  * This library is distributed in the hope that it will be useful,    *
  * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
  * General Public License for more details.                           *
  *                                                                    *
  * You should have received a copy of the GNU General Public License  *
  * along with this library (see file COPYING); if not, write          *
  * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
  * 330, Boston, MA 02111-1307 USA, or contact the author.             *
  *                                                                    *
  **********************************************************************/

// Header file for class GSLRootFinderDeriv
// 
// Created by: moneta  at Sun Nov 21 16:26:03 2004
// 
// Last update: Sun Nov 21 16:26:03 2004
// 
#ifndef ROOT_Math_GSL_RootFinderDeriv
#define ROOT_Math_GSL_RootFinderDeriv


#ifndef ROOT_Math_GSLFunctionAdapter
#include "Math/GSLFunctionAdapter.h"
#endif

#ifndef ROOT_Math_IFunctionfwd
#include "Math/IFunctionfwd.h"
#endif
#ifndef ROOT_Math_IFunction
#include "Math/IFunction.h"
#endif

#ifndef ROOT_Math_IRootFinderMethod
#include "Math/IRootFinderMethod.h"
#endif

#include <iostream>

namespace ROOT {
namespace Math {


   class GSLRootFdFSolver; 
   class GSLFunctionDerivWrapper; 


//_____________________________________________________________________________________
   /**
      Base class for GSL Root-Finding algorithms for one dimensional functions which use function derivatives. 
      For finding the roots users should not use this class directly but instantiate the derived classes, 
      for example  ROOT::Math::Roots::Newton for using the Newton algorithm. 
      All the classes defining the alhorithms are defined in the header Math/RootFinderAlgorithm.h
      They possible types implementing root bracketing algorithms which use function 
      derivatives are: 
      <ul>
         <li>ROOT::Math::Roots::Newton
         <li>ROOT::Math::Roots::Secant
         <li>ROOT::Math::Roots::Steffenson
     </ul>

      See also those classes  for the documentation. 
      See the GSL <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Root-Finding-Algorithms-using-Derivatives.html"> online manual</A> for 
      information on the GSL Root-Finding algorithms
      
      @ingroup RootFinders
   */


class GSLRootFinderDeriv: public IRootFinderMethod {

public: 
   GSLRootFinderDeriv(); 
   virtual ~GSLRootFinderDeriv(); 

private:
   // usually copying is non trivial, so we make this unaccessible
   GSLRootFinderDeriv(const GSLRootFinderDeriv &); 
   GSLRootFinderDeriv & operator = (const GSLRootFinderDeriv &); 

public: 



#if defined(__MAKECINT__) || defined(G__DICTIONARY)     
   bool SetFunction( const IGenFunction & , double , double ) { 
      std::cerr <<"GSLRootFinderDeriv - Error : Algorithm requirs derivatives" << std::endl;  
      return false;
   }
#endif    
     
   bool SetFunction( const IGradFunction & f, double xstart) { 
      const void * p = &f; 
      return SetFunction(  &GSLFunctionAdapter<IGradFunction>::F, &GSLFunctionAdapter<IGradFunction>::Df, &GSLFunctionAdapter<IGradFunction>::Fdf, const_cast<void *>(p), xstart ); 
   }

     
   typedef double ( * GSLFuncPointer ) ( double, void *);
   typedef void ( * GSLFdFPointer ) ( double, void *, double *, double *);
   bool SetFunction( GSLFuncPointer f, GSLFuncPointer df, GSLFdFPointer fdf, void * p, double Root );   

   using IRootFinderMethod::SetFunction;

   /// iterate (return GSL_SUCCESS in case of successful iteration)
   int Iterate(); 

   double Root() const; 

   /// Find the root (return false if failed) 
   bool Solve( int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10);

   /// Return number of iterations
   int Iterations() const {
      return fIter; 
   }

   /// Return the status of last root finding
   int Status() const { return fStatus; }

   const char * Name() const;  

protected:
     
   void SetSolver (  GSLRootFdFSolver * s ); 

   void FreeSolver(); 
     
private: 
     
   GSLFunctionDerivWrapper * fFunction;     
   GSLRootFdFSolver * fS; 
 
   mutable double fRoot; 
   mutable double fPrevRoot; 
   int fIter; 
   int fStatus;    
   bool fValidPoint; 
     
}; 
   
} // namespace Math
} // namespace ROOT


#endif /* ROOT_Math_GSL_RootFinderDeriv */
 GSLRootFinderDeriv.h:1
 GSLRootFinderDeriv.h:2
 GSLRootFinderDeriv.h:3
 GSLRootFinderDeriv.h:4
 GSLRootFinderDeriv.h:5
 GSLRootFinderDeriv.h:6
 GSLRootFinderDeriv.h:7
 GSLRootFinderDeriv.h:8
 GSLRootFinderDeriv.h:9
 GSLRootFinderDeriv.h:10
 GSLRootFinderDeriv.h:11
 GSLRootFinderDeriv.h:12
 GSLRootFinderDeriv.h:13
 GSLRootFinderDeriv.h:14
 GSLRootFinderDeriv.h:15
 GSLRootFinderDeriv.h:16
 GSLRootFinderDeriv.h:17
 GSLRootFinderDeriv.h:18
 GSLRootFinderDeriv.h:19
 GSLRootFinderDeriv.h:20
 GSLRootFinderDeriv.h:21
 GSLRootFinderDeriv.h:22
 GSLRootFinderDeriv.h:23
 GSLRootFinderDeriv.h:24
 GSLRootFinderDeriv.h:25
 GSLRootFinderDeriv.h:26
 GSLRootFinderDeriv.h:27
 GSLRootFinderDeriv.h:28
 GSLRootFinderDeriv.h:29
 GSLRootFinderDeriv.h:30
 GSLRootFinderDeriv.h:31
 GSLRootFinderDeriv.h:32
 GSLRootFinderDeriv.h:33
 GSLRootFinderDeriv.h:34
 GSLRootFinderDeriv.h:35
 GSLRootFinderDeriv.h:36
 GSLRootFinderDeriv.h:37
 GSLRootFinderDeriv.h:38
 GSLRootFinderDeriv.h:39
 GSLRootFinderDeriv.h:40
 GSLRootFinderDeriv.h:41
 GSLRootFinderDeriv.h:42
 GSLRootFinderDeriv.h:43
 GSLRootFinderDeriv.h:44
 GSLRootFinderDeriv.h:45
 GSLRootFinderDeriv.h:46
 GSLRootFinderDeriv.h:47
 GSLRootFinderDeriv.h:48
 GSLRootFinderDeriv.h:49
 GSLRootFinderDeriv.h:50
 GSLRootFinderDeriv.h:51
 GSLRootFinderDeriv.h:52
 GSLRootFinderDeriv.h:53
 GSLRootFinderDeriv.h:54
 GSLRootFinderDeriv.h:55
 GSLRootFinderDeriv.h:56
 GSLRootFinderDeriv.h:57
 GSLRootFinderDeriv.h:58
 GSLRootFinderDeriv.h:59
 GSLRootFinderDeriv.h:60
 GSLRootFinderDeriv.h:61
 GSLRootFinderDeriv.h:62
 GSLRootFinderDeriv.h:63
 GSLRootFinderDeriv.h:64
 GSLRootFinderDeriv.h:65
 GSLRootFinderDeriv.h:66
 GSLRootFinderDeriv.h:67
 GSLRootFinderDeriv.h:68
 GSLRootFinderDeriv.h:69
 GSLRootFinderDeriv.h:70
 GSLRootFinderDeriv.h:71
 GSLRootFinderDeriv.h:72
 GSLRootFinderDeriv.h:73
 GSLRootFinderDeriv.h:74
 GSLRootFinderDeriv.h:75
 GSLRootFinderDeriv.h:76
 GSLRootFinderDeriv.h:77
 GSLRootFinderDeriv.h:78
 GSLRootFinderDeriv.h:79
 GSLRootFinderDeriv.h:80
 GSLRootFinderDeriv.h:81
 GSLRootFinderDeriv.h:82
 GSLRootFinderDeriv.h:83
 GSLRootFinderDeriv.h:84
 GSLRootFinderDeriv.h:85
 GSLRootFinderDeriv.h:86
 GSLRootFinderDeriv.h:87
 GSLRootFinderDeriv.h:88
 GSLRootFinderDeriv.h:89
 GSLRootFinderDeriv.h:90
 GSLRootFinderDeriv.h:91
 GSLRootFinderDeriv.h:92
 GSLRootFinderDeriv.h:93
 GSLRootFinderDeriv.h:94
 GSLRootFinderDeriv.h:95
 GSLRootFinderDeriv.h:96
 GSLRootFinderDeriv.h:97
 GSLRootFinderDeriv.h:98
 GSLRootFinderDeriv.h:99
 GSLRootFinderDeriv.h:100
 GSLRootFinderDeriv.h:101
 GSLRootFinderDeriv.h:102
 GSLRootFinderDeriv.h:103
 GSLRootFinderDeriv.h:104
 GSLRootFinderDeriv.h:105
 GSLRootFinderDeriv.h:106
 GSLRootFinderDeriv.h:107
 GSLRootFinderDeriv.h:108
 GSLRootFinderDeriv.h:109
 GSLRootFinderDeriv.h:110
 GSLRootFinderDeriv.h:111
 GSLRootFinderDeriv.h:112
 GSLRootFinderDeriv.h:113
 GSLRootFinderDeriv.h:114
 GSLRootFinderDeriv.h:115
 GSLRootFinderDeriv.h:116
 GSLRootFinderDeriv.h:117
 GSLRootFinderDeriv.h:118
 GSLRootFinderDeriv.h:119
 GSLRootFinderDeriv.h:120
 GSLRootFinderDeriv.h:121
 GSLRootFinderDeriv.h:122
 GSLRootFinderDeriv.h:123
 GSLRootFinderDeriv.h:124
 GSLRootFinderDeriv.h:125
 GSLRootFinderDeriv.h:126
 GSLRootFinderDeriv.h:127
 GSLRootFinderDeriv.h:128
 GSLRootFinderDeriv.h:129
 GSLRootFinderDeriv.h:130
 GSLRootFinderDeriv.h:131
 GSLRootFinderDeriv.h:132
 GSLRootFinderDeriv.h:133
 GSLRootFinderDeriv.h:134
 GSLRootFinderDeriv.h:135
 GSLRootFinderDeriv.h:136
 GSLRootFinderDeriv.h:137
 GSLRootFinderDeriv.h:138
 GSLRootFinderDeriv.h:139
 GSLRootFinderDeriv.h:140
 GSLRootFinderDeriv.h:141
 GSLRootFinderDeriv.h:142
 GSLRootFinderDeriv.h:143
 GSLRootFinderDeriv.h:144
 GSLRootFinderDeriv.h:145
 GSLRootFinderDeriv.h:146
 GSLRootFinderDeriv.h:147
 GSLRootFinderDeriv.h:148
 GSLRootFinderDeriv.h:149
 GSLRootFinderDeriv.h:150
 GSLRootFinderDeriv.h:151
 GSLRootFinderDeriv.h:152
 GSLRootFinderDeriv.h:153
 GSLRootFinderDeriv.h:154
 GSLRootFinderDeriv.h:155
 GSLRootFinderDeriv.h:156
 GSLRootFinderDeriv.h:157