StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TNumDeriv.h
1 // @(#)root/base:$Name: $:$Id: TNumDeriv.h,v 1.2 2007/10/24 22:45:01 perev Exp $
2 // Author: Victor Perev 05/07/03
3 
4 #ifndef ROOT_TNumDeriv
5 #define ROOT_TNumDeriv
6 #include <math.h>
7 #include "TNamed.h"
8 
9 class TNumDeriv : public TNamed {
10 public:
11  TNumDeriv(const char *name):TNamed(name,"") {fStep=0.01;fIArg=0;fOutLim=0;};
12  virtual ~TNumDeriv(){}
13  virtual Double_t Fcn(Double_t add=0.)=0; //Fcn, must be overloaded
14  Double_t DFcn(Double_t add=0.); //dFcn/dPar
15  void SetOutLimit(int lim=1) {fOutLim=lim ;}
16  void SetStep(Double_t step) {fStep =step ;}
17  void SetIArg(Int_t iarg) {fIArg =iarg ;}
18  Int_t GetIArg() {return fIArg ;}
19 
20  Double_t GetStep() {return fStep ;}
21  static Double_t Tiny();
22  static Double_t Epsilon();
23 
24 private:
25 double numericalDerivative( double x ,double &delta, double &error);
26 
27 protected:
28 Double_t fStep;
29 Int_t fIArg;
30 Int_t fOutLim;
31 static Double_t fgTiny;
32 static Double_t fgEpsilon;
33 ClassDef(TNumDeriv,0)
34 };
35 
36 
37 
38 class TNumDeriv1Test : public TNumDeriv {
39 public:
40  TNumDeriv1Test(double x) :TNumDeriv("DerivTest") {fX=x;SetStep(1e-3);}
41  virtual ~TNumDeriv1Test(){};
42 // virtual Double_t Fcn(Double_t arg){return sin((fX+arg));} //Fcn
43  virtual Double_t Fcn(Double_t arg){return pow(fX+arg,3);} //Fcn
44 //
45  double fX;
46 ClassDef(TNumDeriv1Test,0)
47 };
48 
49 class TNumDeriv2Test : public TNumDeriv {
50 public:
51  TNumDeriv2Test(double x) :TNumDeriv("DerivTest") {fDT=new TNumDeriv1Test(x);fDT->SetStep(0.1);}
52  virtual ~TNumDeriv2Test() {delete fDT;};
53  virtual Double_t Fcn(Double_t arg){return fDT->DFcn(arg);} //Fcn
54 //
55 TNumDeriv1Test *fDT;
56 ClassDef(TNumDeriv2Test,0)
57 };
58 
59 
60 #ifdef __CINT__
61 #pragma link off all globals;
62 #pragma link off all classes;
63 #pragma link off all functions;
64 #pragma link C++ class TNumDeriv;
65 #pragma link C++ class TNumDeriv1Test;
66 #pragma link C++ class TNumDeriv2Test;
67 #endif
68 
69 
70 #endif //ROOT_TNumDeriv
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83