# Integral in TF1

Hi rooters,
I have encounter a problem with TF1::Integral.
here is my code snippet:

//start****
#include <TMath.h>
#include <TF1.h>
double poisson(double *r, double *par);
void bug_integral(){
TF1 tf1=new TF1(“bug”,poisson,0,100,3);
tf1->SetParameters(14.5, 10.2, 1);
for(int n=280; n<300; n++)
cout<<“Integral(0,”<<n<<") = "<Integral(0,n)<<endl;
}
double poisson(double r, double par){
return TMath::Poisson(par[2],par[1]+r[0]par[0]);
}
//end

the output is :
//start******
Processing bug_integral.C…
Integral(0,280) = 2.86932e-05
Integral(0,281) = 2.86937e-05
Integral(0,282) = 2.86941e-05
Integral(0,283) = 2.86946e-05
Integral(0,284) = 2.8695e-05
Integral(0,285) = 2.86954e-05
Integral(0,286) = 2.86958e-05
Integral(0,287) = 2.86962e-05
Integral(0,288) = 2.86966e-05
Integral(0,289) = 2.8697e-05
Integral(0,290) = 9.977e-13
Integral(0,291) = 9.29284e-13
Integral(0,292) = 8.65544e-13
Integral(0,293) = 8.06163e-13
Integral(0,294) = 7.50843e-13
Integral(0,295) = 6.99306e-13
Integral(0,296) = 6.51297e-13
Integral(0,297) = 6.06572e-13
Integral(0,298) = 5.6491e-13
Integral(0,299) = 5.26101e-13
//end******

It seems to me that after n=290, the results of integral are not correctly returned.

can someone point me what’s wrong with it?

Best regards,
Mingshui

Hi,
it is not a bug but a problem of accuracy of the numerical integration.
If you decrease the epsilon value, for example to 1.E-15, by doing as below, you will get a better result

``tf1->Integral(0,n,(double *)0,1.E-15)``

However, why using a numerical integration for that function ? It is an exponential integral (since par[2] = 1) and you can compute it easily the analytically. See en.wikipedia.org/wiki/List_of_in … _functions

If you have a more complex function to integrate, I would eventually use the adaptive numerical integration algorithm of MathMore (class GSLINtegrator) which is superior. See
root.cern.ch/drupal/content/function-integration

Best Regards

Lorenzo

Hi Lorenzo,

It helps.
Thanks very much for this.

Best regards,
Mingshui

What did you want to solve with these integrals What was the challenge?

Hi,
If you have a specific question about TF1::Integral please open a new post.

Lorenzo