1 //////////////////////////////////////////////////////////////////////////////////
3 // Nikolai Amelin, Ludmila Malinina, Timur Pocheptsov (C) JINR/Dubna //
4 // amelin@sunhe.jinr.ru, malinina@sunhe.jinr.ru, pocheptsov@sunhe.jinr.ru //
5 // November. 2, 2005 //
7 // This equation solver class is taken from GEANT4 and modified!! //
8 //////////////////////////////////////////////////////////////////////////////////
9 #ifndef EQUATIONSOLVER_H
10 #define EQUATIONSOLVER_H
13 #define DefaultTolerance 5.0e-14
15 template <class Function>
16 class EquationSolver {
19 enum {kDefaultMaxIter = 100};
20 // default constructor
21 EquationSolver() : fMaxIter(kDefaultMaxIter), fTolerance(DefaultTolerance),
22 fA(0.0), fB(0.0), fRoot(0.0) {};
24 EquationSolver(const Int_t iterations, const Double_t tol) :
25 fMaxIter(iterations), fTolerance(tol),
26 fA(0.0), fB(0.0), fRoot(0.0) {};
29 EquationSolver(const EquationSolver & right);
35 EquationSolver & operator=(const EquationSolver & right);
36 Bool_t operator==(const EquationSolver & right) const;
37 Bool_t operator!=(const EquationSolver & right) const;
39 Int_t GetMaxIterations(void) const {return fMaxIter;}
40 void SetMaxIterations(const Int_t iterations) {fMaxIter=iterations;}
42 Double_t GetTolerance(void) const {return fTolerance;}
43 void SetTolerance(const Double_t epsilon) {fTolerance = epsilon;}
45 Double_t GetIntervalLowerLimit(void) const {return fA;}
46 Double_t GetIntervalUpperLimit(void) const {return fB;}
48 void SetIntervalLimits(const Double_t Limit1, const Double_t Limit2);
50 Double_t GetRoot(void) const {return fRoot;}
52 // Calculates the root by the Brent's method
53 Bool_t Brent(Function& theFunction);
56 Int_t fMaxIter; // Maximum number of iterations
57 Double_t fTolerance; // tolerance (precision)
58 Double_t fA; // interval limits [a,b] which should bracket the root
59 Double_t fB; // interval limits [a,b] which should bracket the root
60 Double_t fRoot; // the equation's root
63 #include "EquationSolver.icc"