1 |
#ifndef TSOLVE_H
|
2 |
#define TSOLVE_H
|
3 |
|
4 |
#include <string>
|
5 |
#include <exception>
|
6 |
|
7 |
|
8 |
class TSolveException: public std::exception
|
9 |
{
|
10 |
private:
|
11 |
std::string except;
|
12 |
public:
|
13 |
TSolveException( const std::string& except_ = std::string() ) : except(except_){}
|
14 |
virtual const char* what() const throw() {
|
15 |
return except.c_str();
|
16 |
}
|
17 |
virtual ~TSolveException() throw(){}
|
18 |
};
|
19 |
|
20 |
//Klasse fuer die Extremwertbestimmung
|
21 |
template <class TClass> class TSolve{
|
22 |
|
23 |
public:
|
24 |
|
25 |
TSolve(TClass* pt2Object, double(TClass::*fpt)(double, const double*), const double*par=0, double l=0., double r=0.):
|
26 |
_par(par),_left(l),_right(r),epsilon(0.0001)
|
27 |
{ _pt2Object = pt2Object; _function=fpt;};
|
28 |
|
29 |
~TSolve(){}; //Destructor
|
30 |
|
31 |
double operator()();
|
32 |
|
33 |
double GetLeft(){return _left;};
|
34 |
double GetRight(){return _right;};
|
35 |
void SetLeft(double const left){_left=left;};
|
36 |
void SetRight(double const right){_right=right;};
|
37 |
void SetPar(double const *par){_par=par;};
|
38 |
void SetPrecision(double const eps){epsilon=eps;};
|
39 |
void BracketFunction(double l, double r);
|
40 |
|
41 |
struct exception {
|
42 |
std::string except;
|
43 |
std::string what(){return except;}
|
44 |
exception( const std::string& except_ = std::string() )
|
45 |
: except(except_){} };
|
46 |
private:
|
47 |
TClass* _pt2Object; // pointer to object
|
48 |
|
49 |
bool _isBracketed(double l, double r);
|
50 |
double _bisection(int n=100);
|
51 |
|
52 |
double (TClass::*_function)(double, const double*);
|
53 |
const double *_par;
|
54 |
double _left, _right;
|
55 |
double epsilon;
|
56 |
};
|
57 |
|
58 |
|
59 |
#endif
|