# How to update fit parameters?

Hello!

I want to fit my data by nonlinear function, so I must define start parameters.
For example:

``````Double_t fitFunction(Double_t *x,Double_t *par)
{
//just for example
return Exp(x[0]*par[0]) + par[1] ;
}

void Fit ()
{
vector<double> xv;
vector<double> yv;

//fill vectors ...

TGraph * gr = new TGraph(xv.size(), &xv[0], &yv[0]);
TF1 *fitFcn = new TF1("fitFcn", fitFunction, 0, 1, 2);

fitFcn->SetParameter(0, 0.5);
fitFcn->SetParLimits(0, 0, 1);

fitFcn->SetParameter(1, 0.5);
fitFcn->SetParLimits(1, 0, 1);

gr->Fit("fitFcn", "R");
gr->Draw("AP");
}``````

My fit is bad, so I want to define new start parameters.
I try to do this in the following manner:

``````void Fit ()
{
// old code
vector<double> xv;
vector<double> yv;

//fill vectors ...

TGraph * gr = new TGraph(xv.size(), &xv[0], &yv[0]);
TF1 *fitFcn = new TF1("fitFcn", fitFunction, 0, 1, 2);

fitFcn->SetParameter(0, 0.5);
fitFcn->SetParLimits(0, 0, 1);

fitFcn->SetParameter(1, 0.5);
fitFcn->SetParLimits(1, 0, 1);

gr->Fit("fitFcn", "R");

//new code
if( fitFcn->GetChisquare() / fitFcn->GetNDF() > 1)
{
fitFcn->SetParameter(0, 0.2);//new start value
fitFcn->SetParLimits(0, 0, 1);

fitFcn->SetParameter(1, 0.8);////new start value
fitFcn->SetParLimits(1, 0, 1);

gr->Fit("fitFcn", "R");
}

gr->Draw("AP");
}``````

Unfortunately, this method does not work and my fit the same.
But I donâ€™t know for sure: my new code is wrong or my code is right and minimiser found the same minimum.

How to define new parameters properly?

Hi,

the procedure is correct. What is the output of the minimiser in the two cases?