Logo ROOT   6.08/07
Reference Guide
testIntegration.cxx
Go to the documentation of this file.
1 #include "Math/Integrator.h"
4 #include "Math/Functor.h"
5 #include "Math/GaussIntegrator.h"
6 
7 #include <cmath>
8 
9 const double ERRORLIMIT = 1E-3;
10 
11 
12 double f(double x) {
13  return x;
14 }
15 
16 double f2(const double * x) {
17  return x[0] + x[1];
18 }
19 
20 void printTestResult(std::ostream & os, const char * type, int status) {
21  os << "Test of " << type << "\t: \t";
22  if (!status) os << "OK" << std::endl;
23  else os << "FAILED";
24  os << std::endl << std::endl;
25 }
26 
27 
29 
30  const double RESULT = 0.5;
31  int status = 0;
32 
33 
36  ig.SetFunction(wf);
37  double val = ig.Integral(0,1);
38  std::cout << "GSL adaptive sing. integral result is \t" << val << std::endl;
39  status += std::fabs(val-RESULT) > ERRORLIMIT;
40 
42  ig2.SetFunction(wf);
43  val = ig2.Integral(0,1);
44  std::cout << "GSL non-adaptiveintegral result is \t" << val << std::endl;
45  status += std::fabs(val-RESULT) > ERRORLIMIT;
46 
48  val = ig3.Integral(0,1);
49  std::cout << "GSL adaptive integral result is \t" << val << std::endl;
50  status += std::fabs(val-RESULT) > ERRORLIMIT;
51 
52  //ROOT::Math::GaussIntegrator ig4;
54  ig4.SetFunction(wf);
55  val = ig4.Integral(0,1);
56  std::cout << "Cernlib Gauss integral result is \t" << val << std::endl;
57  status += std::fabs(val-RESULT) > ERRORLIMIT;
58 
60  ig5.SetFunction(wf);
61  val = ig5.Integral(0,1);
62  std::cout << "Gauss-Legendre integral result is \t" << val << std::endl;
63  status += std::fabs(val-RESULT) > ERRORLIMIT;
64 
65  printTestResult(std::cerr,"one-dimensional integration ",status);
66  return status;
67 }
68 
70 
71  const double RESULT = 1.0;
72  int status = 0;
73 
74  ROOT::Math::Functor wf(&f2,2);
75  double a[2] = {0,0};
76  double b[2] = {1,1};
77 
79  ig.SetFunction(wf);
80  double val = ig.Integral(a,b);
81  std::cout << "Cernlib Adaptive integral result is " << val << std::endl;
82  status += std::fabs(val-RESULT) > ERRORLIMIT;
83 
85  ig2.SetFunction(wf);
86  val = ig2.Integral(a,b);
87  std::cout << "GSL VEGAS integral result is " << val << std::endl;
88  status += std::fabs(val-RESULT) > ERRORLIMIT;
89 
91  val = ig3.Integral(a,b);
92  std::cout << "GSL PLAIN integral result is " << val << std::endl;
93  status += std::fabs(val-RESULT) > ERRORLIMIT;
94 
96  val = ig4.Integral(a,b);
97  std::cout << "GSL MISER integral result is " << val << std::endl;
98  status += std::fabs(val-RESULT) > ERRORLIMIT;
99 
100  printTestResult(std::cerr,"multi-dimensional integration",status);
101 
102  return status;
103 }
104 
105 int main() {
106  int status = 0;
107 
108  status += testIntegration1D();
109  status += testIntegrationMultiDim();
110 
111  return status;
112 }
113 
void printTestResult(std::ostream &os, const char *type, int status)
Documentation for class Functor class.
Definition: Functor.h:394
double Integral(const double *xmin, const double *xmax)
evaluate the integral with the previously given function between xmin[] and xmax[] ...
TArc * a
Definition: textangle.C:12
Double_t x[n]
Definition: legend1.C:17
int testIntegration1D()
void SetFunction(Function &f, unsigned int dim)
set integration function using a generic function implementing the operator()(double *x) The dimensio...
double Integral(Function &f, double a, double b)
evaluate the Integral of a function f over the defined interval (a,b)
Definition: Integrator.h:506
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
User Class for performing numerical integration of a function in one dimension.
Definition: Integrator.h:102
Double_t E()
Definition: TMath.h:54
int testIntegrationMultiDim()
double f(double x)
int type
Definition: TGX11.cxx:120
const double ERRORLIMIT
void SetFunction(Function &f)
method to set the a generic integration function
Definition: Integrator.h:499
User class for performing multidimensional integration.
double f2(const double *x)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Functor1D class for one-dimensional functions.
Definition: Functor.h:494
int main()