00001 // @(#)root/mathmore:$Id: GSLRootFinder.h 32583 2010-03-12 09:57:42Z moneta $ 00002 // Author: 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 GSLRootFinder 00026 // 00027 // Created by: moneta at Sun Nov 14 11:27:11 2004 00028 // 00029 // Last update: Sun Nov 14 11:27:11 2004 00030 // 00031 #ifndef ROOT_Math_GSLRootFinder 00032 #define ROOT_Math_GSLRootFinder 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 00043 #ifndef ROOT_Math_IRootFinderMethod 00044 #include "Math/IRootFinderMethod.h" 00045 #endif 00046 00047 #include <iostream> 00048 00049 namespace ROOT { 00050 namespace Math { 00051 00052 00053 class GSLRootFSolver; 00054 class GSLFunctionWrapper; 00055 00056 00057 //________________________________________________________________________________________________________ 00058 /** 00059 Base class for GSL Root-Finding algorithms for one dimensional functions which do not use function derivatives. 00060 For finding the roots users should not use this class directly but instantiate the derived classes, 00061 for example ROOT::Math::Roots::Brent for using the Brent algorithm. 00062 All the classes defining the alhorithms are defined in the header Math/RootFinderAlgorithm.h 00063 They possible types implementing root bracketing algorithms which they do not require function 00064 derivatives are: 00065 <ul> 00066 <li>ROOT::Math::Roots::Bisection 00067 <li>ROOT::Math::Roots::FalsePos 00068 <li>ROOT::Math::Roots::Brent 00069 </ul> 00070 00071 See also the specific classes for the documentation. 00072 See the GSL <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Root-Bracketing-Algorithms.html"> online manual</A> for 00073 information on the GSL Root-Finding algorithms 00074 00075 @ingroup RootFinders 00076 */ 00077 00078 00079 class GSLRootFinder: public IRootFinderMethod { 00080 00081 public: 00082 GSLRootFinder(); 00083 virtual ~GSLRootFinder(); 00084 00085 private: 00086 // usually copying is non trivial, so we make this unaccessible 00087 GSLRootFinder(const GSLRootFinder &); 00088 GSLRootFinder & operator = (const GSLRootFinder &); 00089 00090 public: 00091 00092 00093 #if defined(__MAKECINT__) || defined(G__DICTIONARY) 00094 bool SetFunction( const IGradFunction & , double ) { 00095 std::cerr <<"GSLRootFinder - Error : this method must be used with a Root Finder algorithm using derivatives" << std::endl; 00096 return false; 00097 } 00098 #endif 00099 00100 bool SetFunction( const IGenFunction & f, double xlow, double xup); 00101 00102 typedef double ( * GSLFuncPointer ) ( double, void *); 00103 bool SetFunction( GSLFuncPointer f, void * params, double xlow, double xup); 00104 00105 using IRootFinderMethod::SetFunction; 00106 00107 // iterate to find ROOTS return GSL_CONTINUE if iteration was succesfull or another error 00108 int Iterate(); 00109 00110 double Root() const; 00111 00112 //double XLower() const; 00113 00114 //double XUpper() const; 00115 00116 /// Find the root 00117 bool Solve( int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10); 00118 00119 /// Return number of iterations 00120 int Iterations() const { 00121 return fIter; 00122 } 00123 00124 /// Return the status of last root finding 00125 int Status() const { return fStatus; } 00126 00127 const char * Name() const; 00128 00129 00130 protected: 00131 00132 00133 void SetSolver ( GSLRootFSolver * s ); 00134 00135 void FreeSolver(); 00136 00137 private: 00138 00139 GSLFunctionWrapper * fFunction; 00140 GSLRootFSolver * fS; 00141 00142 double fRoot; 00143 double fXlow; 00144 double fXup; 00145 int fIter; 00146 int fStatus; 00147 bool fValidInterval; 00148 00149 }; 00150 00151 } // namespace Math 00152 } // namespace ROOT 00153 00154 00155 #endif /* ROOT_Math_GSLRootFinder */