28 std::vector<double> p =
par;
31 for (
unsigned int i = 1; i < p.size() ; ++i) {
32 p[i] = par[i-1]/double(i);
36 return (*func)(
b)-(*func)(
a);
58 std::vector<double> p(3);
67 std::cout <<
"Exact value " << exactresult << std::endl << std::endl;
78 std::cout.precision(20);
80 std::cout <<
"Adaptive singular integration:" << std::endl;
82 if (status) std::cout <<
"Error - Return code " << ig.
Status() << std::endl;
83 std::cout <<
"Result " << value <<
" +/- " << ig.
Error() << std::endl << std::endl;
85 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Adaptive integration failed on a polynomial function");
93 std::cout <<
"Adaptive Gauss61 integration:" << std::endl;
95 if (status) std::cout <<
"Error - Return code " << ig.
Status() << std::endl;
96 std::cout <<
"Result " << value <<
" +/- " << ig2.
Error() << std::endl << std::endl;
98 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Adaptive GAUSS61 integration failed on a polynomial function");
101 std::cout <<
"Testing SetFunction member function" << std::endl;
108 std::cout <<
"Result " << ig3.
Integral( 0, 3) <<
" +/- " << ig3.
Error() << std::endl;
110 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Default Adaptive integration failed on a polynomial function");
115 std::cout <<
"\nTesting a singular function: 1/sqrt(x)" << std::endl;
122 std::cout <<
"Error integrating a singular function " << std::endl;
124 std::cout <<
"Result:(0,1] = " << r <<
" +/- " << ig.
Error() <<
" (should be 2) " << std::endl;
127 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Singular Adaptive integration failed on 1./sqrt(x)");
129 double singularPts[3] = {-1,0,1};
130 std::vector<double> sp(singularPts, singularPts+3);
134 std::cout <<
"Error integrating a singular function using vector of points" << std::endl;
136 std::cout <<
"Result:[-1,1] = " << r2 <<
" +/- " << ig.
Error() <<
" (should be 4) " << std::endl;
138 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Adaptive integration with singular points failed on 1./sqrt(x)");
141 std::vector<double> sp2(2);
142 sp2[0] = -1.; sp2[1] = -0.5;
144 std::cout <<
"Result on [-1,-0.5] = " << r3 <<
" +/- " << ig.
Error() <<
" (should be 0.5857) " << std::endl;
147 if (status)
MATH_ERROR_MSG(
"testGSLIntegration",
"Adaptive integration with singular points 2 failed on 1./sqrt(x)");
157 std::cout <<
"\n\n***************************************************************\n";
158 std::cout <<
"Test integration performances....\n\n";
162 double p[3] = {2,3,4};
167 double x1 = 0;
double x2 = 10;
168 double dx = (x2-
x1)/
double(n);
174 for (
int i = 0; i <
n; ++i) {
175 double x = x1 + dx*i;
179 std::cout <<
"Time using ROOT::Math::Integrator :\t" << timer.
RealTime() << std::endl;
180 int pr = std::cout.precision(18); std::cout << s1 << std::endl; std::cout.precision(pr);
184 for (
int i = 0; i <
n; ++i) {
186 double x = x1 + dx*i;
190 std::cout <<
"Time using ROOT::Math::Integrator(2):\t" << timer.
RealTime() << std::endl;
191 pr = std::cout.precision(18); std::cout << s1 << std::endl; std::cout.precision(pr);
194 TF1 f2(
"pol",
"pol2",0,10);
199 for (
int i = 0; i <
n; ++i) {
200 double x = x1 + dx*i;
204 std::cout <<
"Time using TF1::Integral :\t\t" << timer.
RealTime() << std::endl;
205 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
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
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]