I want to build a TF1 function from 2 TFormula function:(for newbie practice)
{
auto fa1 = new TFormula("fa1","[0]*cos([1]*x)");
fa1->SetParameter(0,7);
fa1->SetParameter(1,6);
auto fa2 = new TFormula("fa2","[2]*sin([3]*x)");
fa2->SetParameter(2,5);
fa2->SetParameter(3,4);
auto f1 = new TF1("f1","fa1+fa2",-TMath::Pi(),TMath::Pi());
auto f2 = new TF1("f2","7*cos(6*x)+5*sin(4*x)",-TMath::Pi(),TMath::Pi());
f2->SetLineColor(kBlue);
f1->Draw();
f2->Draw("same")
}
However, it seems that the f1 function only contains the fa1 part, and whatever I do, fa2 can’t be correctly added to f1(means f1 only draws the cosine plot) .I’m curious about why I set parameter in the same way but have different effects. And what should I do to modify the code?
By the way, what’s the difference between TF1 and TFormula class? I don’t know how to choose them.