# In TF2 how to get x and y value corresponding to the maximimum value of the function or any value of the function

Hello Experts
I have defined a simple TF2 function(say f2) and I get the maximum value of the function using GetMaximum(). But I couldn’t find the x and y values corresponding to that maximum
value of the function or any value of function. So please point me if there is any inbuilt function in root for TF2 to get x and y value corresponding to the function value.

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

It looks like TF2 has a method TF2::GetMaximumXY which does what you need.
https://root.cern.ch/doc/master/classTF2.html#a038c91ab195a2ea5e81748f7ac5014d7

Hi, I am trying to get x and y value corresponding to the maximum value of the function. The method you suggested TF2::GetMaximumXY, gives the value of the function for the given x and y. Here is the function bellow

``````void test1()
{
TF2 *f2= new TF2("f2","(-(8.83+x*0.2169+y*0.8139)+(10*log(8.83+x*0.2169+y*0.8139))-(10*log(10))+10-(6.342+x*0.05957+y*2.5286)+(6*log(6.342+x*0.05957+y*2.5286))-(6*log(6))+6)",-20,50,-2.,2.);

f2->Draw();

Double_t co=-0.1;
Double_t coh=2;
cout<<"GetMaximum=  "<<f2->GetMaximum()<<endl;
cout<<"GetMaximumXY=  "<<f2->GetMaximumXY(co,coh)<<endl;
}

``````

Method defination of TF2::GetMaximumXY
https://root.cern.ch/doc/master/TF2_8cxx_source.html

Correct me if I am missing something.

``````std::cout << "GetMaximumXY = " << f2->GetMaximumXY(co, coh) << " at ( " << co << " , " << coh << " )" << std::endl;