Find minimum of a TF1 function with parameters

Hi experts,
I defined a TF1 type function with 2 paramerters and wanna get back its minimun and the variable at which the function has the minimum. My code is as below, but it doesn’t works, and print out: min: nan minx: 0. How can I fix it up?
Best regards

Double_t myfunction(Double_t *x, Double_t *par)
		{
		   Float_t xx =x[0];
		   Double_t f = TMath::Abs(par[0]*sin(par[1]*xx)/xx);
		   return f;
		}
void find_min(){
	
    TF1 *fun= new TF1("fun",myfunction,0,10,2);
    fun->SetParameters(1,2);
    fun->Draw();
    double min=fun->GetMinimum(0,2);
    double minx=fun->GetMinimumX(0,2);
    cout<<"min: "<<min<<" minx: "<<minx<<endl;

}

You must not use “0” as the “xmin” (e.g., try with “1.e-7”).

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