Get maximum of a function

I want to calculate the maxima of a function. But when I apply the below code it gives the highest value of x in the range ( 4 here in the macro). Can you please tell me how to do it.

TF1 *f3 = new TF1(“f3”,“f0/f1”,0,4.); // Division of two functions
Double_t c = f3->GetMaximumX(); //GetXmax();
std::cout << "c = "<< c << std::endl;

The answer I get is c = 4. The analytical answer of 1.02.

Thank you

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

I’m not sure what you mean. Try:

  TF1 *f3 = new TF1("f3", "TMath::DiLog(x)", 0., 10.);
  Double_t c = f3->GetMaximumX();
  std::cout << "c = "<< c << std::endl;
  std::cout << "f3(c) = "<< f3->Eval(c) << std::endl;
  std::cout << "f3 maximum = "<< f3->GetMaximum() << std::endl;

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.