]>
Commit | Line | Data |
---|---|---|
03896fc4 | 1 | ////////////////////////////////////////////////////////////////////////////////// |
2 | // // | |
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 // | |
6 | // // | |
7 | // This equation solver class is taken from GEANT4 and modified!! // | |
8 | ////////////////////////////////////////////////////////////////////////////////// | |
9 | #ifndef EQUATIONSOLVER_H | |
10 | #define EQUATIONSOLVER_H | |
b1c2e580 | 11 | #include <Rtypes.h> |
b1c2e580 | 12 | |
13 | #define DefaultTolerance 5.0e-14 | |
14 | ||
15 | template <class Function> | |
03896fc4 | 16 | class EquationSolver { |
b1c2e580 | 17 | |
18 | public: | |
03896fc4 | 19 | enum {kDefaultMaxIter = 100}; |
b1c2e580 | 20 | // default constructor |
03896fc4 | 21 | EquationSolver() : fMaxIter(kDefaultMaxIter), fTolerance(DefaultTolerance), |
b1c2e580 | 22 | fA(0.0), fB(0.0), fRoot(0.0) {}; |
23 | ||
03896fc4 | 24 | EquationSolver(const Int_t iterations, const Double_t tol) : |
b1c2e580 | 25 | fMaxIter(iterations), fTolerance(tol), |
26 | fA(0.0), fB(0.0), fRoot(0.0) {}; | |
27 | ||
28 | // copy constructor | |
03896fc4 | 29 | EquationSolver(const EquationSolver & right); |
b1c2e580 | 30 | |
31 | // destructor | |
03896fc4 | 32 | ~EquationSolver() {}; |
b1c2e580 | 33 | |
34 | // operators | |
03896fc4 | 35 | EquationSolver & operator=(const EquationSolver & right); |
36 | Bool_t operator==(const EquationSolver & right) const; | |
37 | Bool_t operator!=(const EquationSolver & right) const; | |
b1c2e580 | 38 | |
39 | Int_t GetMaxIterations(void) const {return fMaxIter;} | |
40 | void SetMaxIterations(const Int_t iterations) {fMaxIter=iterations;} | |
41 | ||
42 | Double_t GetTolerance(void) const {return fTolerance;} | |
43 | void SetTolerance(const Double_t epsilon) {fTolerance = epsilon;} | |
44 | ||
45 | Double_t GetIntervalLowerLimit(void) const {return fA;} | |
46 | Double_t GetIntervalUpperLimit(void) const {return fB;} | |
47 | ||
48 | void SetIntervalLimits(const Double_t Limit1, const Double_t Limit2); | |
49 | ||
50 | Double_t GetRoot(void) const {return fRoot;} | |
51 | ||
52 | // Calculates the root by the Brent's method | |
53 | Bool_t Brent(Function& theFunction); | |
03896fc4 | 54 | |
55 | private: | |
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 | |
b1c2e580 | 61 | }; |
62 | ||
63 | #include "EquationSolver.icc" | |
64 | ||
65 | #endif |