GSLRootFinderDeriv.h

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: GSLRootFinderDeriv.h 32583 2010-03-12 09:57:42Z moneta $
00002 // Authors: L. Moneta, A. Zsenei   08/2005 
00003 
00004  /**********************************************************************
00005   *                                                                    *
00006   * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
00007   *                                                                    *
00008   * This library is free software; you can redistribute it and/or      *
00009   * modify it under the terms of the GNU General Public License        *
00010   * as published by the Free Software Foundation; either version 2     *
00011   * of the License, or (at your option) any later version.             *
00012   *                                                                    *
00013   * This library is distributed in the hope that it will be useful,    *
00014   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00015   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00016   * General Public License for more details.                           *
00017   *                                                                    *
00018   * You should have received a copy of the GNU General Public License  *
00019   * along with this library (see file COPYING); if not, write          *
00020   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
00021   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
00022   *                                                                    *
00023   **********************************************************************/
00024 
00025 // Header file for class GSLRootFinderDeriv
00026 // 
00027 // Created by: moneta  at Sun Nov 21 16:26:03 2004
00028 // 
00029 // Last update: Sun Nov 21 16:26:03 2004
00030 // 
00031 #ifndef ROOT_Math_GSL_RootFinderDeriv
00032 #define ROOT_Math_GSL_RootFinderDeriv
00033 
00034 
00035 #ifndef ROOT_Math_GSLFunctionAdapter
00036 #include "Math/GSLFunctionAdapter.h"
00037 #endif
00038 
00039 #ifndef ROOT_Math_IFunctionfwd
00040 #include "Math/IFunctionfwd.h"
00041 #endif
00042 #ifndef ROOT_Math_IFunction
00043 #include "Math/IFunction.h"
00044 #endif
00045 
00046 #ifndef ROOT_Math_IRootFinderMethod
00047 #include "Math/IRootFinderMethod.h"
00048 #endif
00049 
00050 #include <iostream>
00051 
00052 namespace ROOT {
00053 namespace Math {
00054 
00055 
00056    class GSLRootFdFSolver; 
00057    class GSLFunctionDerivWrapper; 
00058 
00059 
00060 //_____________________________________________________________________________________
00061    /**
00062       Base class for GSL Root-Finding algorithms for one dimensional functions which use function derivatives. 
00063       For finding the roots users should not use this class directly but instantiate the derived classes, 
00064       for example  ROOT::Math::Roots::Newton for using the Newton algorithm. 
00065       All the classes defining the alhorithms are defined in the header Math/RootFinderAlgorithm.h
00066       They possible types implementing root bracketing algorithms which use function 
00067       derivatives are: 
00068       <ul>
00069          <li>ROOT::Math::Roots::Newton
00070          <li>ROOT::Math::Roots::Secant
00071          <li>ROOT::Math::Roots::Steffenson
00072      </ul>
00073 
00074       See also those classes  for the documentation. 
00075       See the GSL <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Root-Finding-Algorithms-using-Derivatives.html"> online manual</A> for 
00076       information on the GSL Root-Finding algorithms
00077       
00078       @ingroup RootFinders
00079    */
00080 
00081 
00082 class GSLRootFinderDeriv: public IRootFinderMethod {
00083 
00084 public: 
00085    GSLRootFinderDeriv(); 
00086    virtual ~GSLRootFinderDeriv(); 
00087 
00088 private:
00089    // usually copying is non trivial, so we make this unaccessible
00090    GSLRootFinderDeriv(const GSLRootFinderDeriv &); 
00091    GSLRootFinderDeriv & operator = (const GSLRootFinderDeriv &); 
00092 
00093 public: 
00094 
00095 
00096 
00097 #if defined(__MAKECINT__) || defined(G__DICTIONARY)     
00098    bool SetFunction( const IGenFunction & , double , double ) { 
00099       std::cerr <<"GSLRootFinderDeriv - Error : Algorithm requirs derivatives" << std::endl;  
00100       return false;
00101    }
00102 #endif    
00103      
00104    bool SetFunction( const IGradFunction & f, double xstart) { 
00105       const void * p = &f; 
00106       return SetFunction(  &GSLFunctionAdapter<IGradFunction>::F, &GSLFunctionAdapter<IGradFunction>::Df, &GSLFunctionAdapter<IGradFunction>::Fdf, const_cast<void *>(p), xstart ); 
00107    }
00108 
00109      
00110    typedef double ( * GSLFuncPointer ) ( double, void *);
00111    typedef void ( * GSLFdFPointer ) ( double, void *, double *, double *);
00112    bool SetFunction( GSLFuncPointer f, GSLFuncPointer df, GSLFdFPointer fdf, void * p, double Root );   
00113 
00114    using IRootFinderMethod::SetFunction;
00115 
00116    /// iterate (return GSL_SUCCESS in case of succesfull iteration)
00117    int Iterate(); 
00118 
00119    double Root() const; 
00120 
00121    /// Find the root (return false if failed) 
00122    bool Solve( int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10);
00123 
00124    /// Return number of iterations
00125    int Iterations() const {
00126       return fIter; 
00127    }
00128 
00129    /// Return the status of last root finding
00130    int Status() const { return fStatus; }
00131 
00132    const char * Name() const;  
00133 
00134 protected:
00135      
00136    void SetSolver (  GSLRootFdFSolver * s ); 
00137 
00138    void FreeSolver(); 
00139      
00140 private: 
00141      
00142    GSLFunctionDerivWrapper * fFunction;     
00143    GSLRootFdFSolver * fS; 
00144  
00145    mutable double fRoot; 
00146    mutable double fPrevRoot; 
00147    int fIter; 
00148    int fStatus;    
00149    bool fValidPoint; 
00150      
00151 }; 
00152    
00153 } // namespace Math
00154 } // namespace ROOT
00155 
00156 
00157 #endif /* ROOT_Math_GSL_RootFinderDeriv */

Generated on Tue Jul 5 14:25:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1