I have a question concerning TF1-objects.
I have two functions TF1 func1, TF1 func2, a simple example would be:
TF1* func1 = new TF1(“f1”,"[0]xx");
func1->SetParameter(0,5);
TF1* func2 = new TF1(“f2”,"[0]*x+3");
func2->SetParameter(0,3);
Is there a way to calculate all x by solving the equation func1(x)=func2(x)?
Respectively, is there a way to calculate all x : f(x) := func1(x) - func2 (x)= 0?
I tried a simple exercise with the following macro. That’s really a toy I am sure there is better ways
{
Double_t x1=-10, x2=10;
Double_t s=0.0001;
Double_t eps=0.0005;
TF1* f1 = new TF1("f1","[0]*x*x",x1,x2);
f1->SetParameter(0,5);
TF1* f2 = new TF1("f2","[0]*x+3",x1,x2);
f2->SetParameter(0,3);
Double_t x = x1;
while (x<x2) {
if (TMath::Abs(f1->Eval(x)-f2->Eval(x)) < eps) {
printf("f1 and f2 cross at x = %g %g\n",x,f1->Eval(x)-f2->Eval(x));
}
x=x+s;
}
}