29 std::vector<double> p =
par;
32 for (
unsigned int i = 1; i < p.size() ; ++i) {
33 p[i] = par[i-1]/double(i);
37 return (*func)(
b)-(*func)(
a);
59 std::vector<double> p(3);
68 std::cout <<
"Exact value " << exactresult << std::endl << std::endl;
79 std::streamsize ss = std::cout.precision();
80 std::cout.precision(20);
82 std::cout <<
"Adaptive singular integration:" << std::endl;
84 if (status) std::cout <<
"Error - Return code " << ig.
Status() << std::endl;
85 std::cout <<
"Result " << value <<
" +/- " << ig.
Error() << std::endl << std::endl;
87 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Adaptive integration failed on a polynomial function");
95 std::cout <<
"Adaptive Gauss61 integration:" << std::endl;
97 if (status) std::cout <<
"Error - Return code " << ig.
Status() << std::endl;
98 std::cout <<
"Result " << value <<
" +/- " << ig2.
Error() << std::endl << std::endl;
100 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Adaptive GAUSS61 integration failed on a polynomial function");
103 std::cout <<
"Testing SetFunction member function" << std::endl;
110 std::cout <<
"Result " << ig3.
Integral( 0, 3) <<
" +/- " << ig3.
Error() << std::endl;
112 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Default Adaptive integration failed on a polynomial function");
117 std::cout <<
"\nTesting a singular function: 1/sqrt(x)" << std::endl;
124 std::cout <<
"Error integrating a singular function " << std::endl;
126 std::cout <<
"Result:(0,1] = " << r <<
" +/- " << ig.
Error() <<
" (should be 2) " << std::endl;
129 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Singular Adaptive integration failed on 1./sqrt(x)");
131 double singularPts[3] = {-1,0,1};
132 std::vector<double> sp(singularPts, singularPts+3);
136 std::cout <<
"Error integrating a singular function using vector of points" << std::endl;
138 std::cout <<
"Result:[-1,1] = " << r2 <<
" +/- " << ig.
Error() <<
" (should be 4) " << std::endl;
140 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Adaptive integration with singular points failed on 1./sqrt(x)");
143 std::vector<double> sp2(2);
144 sp2[0] = -1.; sp2[1] = -0.5;
146 std::cout <<
"Result on [-1,-0.5] = " << r3 <<
" +/- " << ig.
Error() <<
" (should be 0.5857) " << std::endl;
149 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Adaptive integration with singular points 2 failed on 1./sqrt(x)");
151 std::cout.precision(ss);
159 std::cout <<
"\n\n***************************************************************\n";
160 std::cout <<
"Test integration performances....\n\n";
164 double p[3] = {2,3,4};
169 double x1 = 0;
double x2 = 10;
170 double dx = (x2-
x1)/
double(n);
176 for (
int i = 0; i <
n; ++i) {
177 double x = x1 + dx*i;
181 std::cout <<
"Time using ROOT::Math::Integrator :\t" << timer.
RealTime() << std::endl;
182 int pr = std::cout.precision(18); std::cout << s1 << std::endl; std::cout.precision(pr);
186 for (
int i = 0; i <
n; ++i) {
188 double x = x1 + dx*i;
192 std::cout <<
"Time using ROOT::Math::Integrator(2):\t" << timer.
RealTime() << std::endl;
193 pr = std::cout.precision(18); std::cout << s1 << std::endl; std::cout.precision(pr);
196 TF1 f2(
"pol",
"pol2",0,10);
201 for (
int i = 0; i <
n; ++i) {
202 double x = x1 + dx*i;
206 std::cout <<
"Time using TF1::Integral :\t\t" << timer.
RealTime() << std::endl;
207 pr = std::cout.precision(18); std::cout << s1 << std::endl; std::cout.precision(pr);
double exactIntegral(const std::vector< double > &par, double a, double b)
double Result() const
return the Result of the last Integral calculation
virtual void SetParameters(const Double_t *params)
double singularFunction(double x)
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
R__EXTERN Int_t gErrorIgnoreLevel
Namespace for new ROOT classes and functions.
int Status() const
return the Error Status of the last Integral calculation
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
double Integral(const IGenFunction &f, double a, double b)
evaluate the Integral of a function f over the defined interval (a,b)
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
static const double x2[5]
void Stop()
Stop the stopwatch.
unsigned int r3[N_CITIES]
Class for performing numerical integration of a function in one dimension.
#define MATH_ERROR_MSG(loc, str)
double Error() const
return the estimate of the absolute Error of the last Integral calculation
double Integral(Function &f, double a, double b)
evaluate the Integral of a function f over the defined interval (a,b)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
virtual void SetParameters(const double *p)
Set the parameter values.
void SetFunction(const IGenFunction &f)
method to set the a generic integration function
User Class for performing numerical integration of a function in one dimension.
Parametric Function class describing polynomials of order n.
double Error() const
return the estimate of the absolute Error of the last Integral calculation
static const double x1[5]
double func(double *x, double *p)
Namespace for new Math classes and functions.
void SetFunction(Function &f)
method to set the a generic integration function
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
IntegratorOneDim Integrator
Functor1D class for one-dimensional functions.
unsigned int r2[N_CITIES]