Integrate a TF2 function over one variable


I need to integrate a TF2 function over one of the
variables only. How can I do it??

For Example:
TF2 f2 = new TF2(“f2”, "TMath::Cos(xy)/(x+y)", 1,1.5, 1,1.5);
I need to integrate y over the whole interval [1,1.5] to get a function
that depends on x only.


Use intermediate class TF12. This class behaves like a TF1, referencing a TF2 for a fixed value of x or y. See example below


void f12() { TF2 *f2 = new TF2("f2", "TMath::Cos(x*y)/(x+y)", 1,1.5, 1,1.5); TF12 *f12 = new TF12("f12",f2,0.1,"y"); Double_t result = f12->Integral(1,1.5); printf("Integral of F2 over x for y=0.1 = %g\n",result); }