Root SetParameters

If I try to fit a function to a given data, and if i already define the parameters of the function , after fitting I am getting different parameters ?? I did not understand this part.
and also If I fit the function without setting parameters , after fitting I did not get the same parameters which I got earlier (not too much variation though).

void plot(){
    TGraph *gr = new TGraph("data.txt");
    TF1 *fn = new TF1("fn","[2]*x*x + [1]*x + [0]" , -10 , 10);

Can you post data.txt ?

data.txt (255 Bytes)

Also what it means to get new parameters for a fit, if we have already defined parameters?

I get this:

Processing plot.C...

Minimizer is Minuit / Migrad
Chi2                      =  0.000397134
NDf                       =           19
Edm                       =  3.36476e-22
NCalls                    =           67
p0                        =    0.0266482   +/-   0.0253677   
p1                        =     0.595907   +/-   0.259264    
p2                        =      5.39565   +/-   0.644357    

It seems ok seems to me. Minuit adjusted the parameters to fit the dtata points.

yes but ain’t these parameters the coefficients of x^2 , x, constant?? which we have already set in our code. so these parameters should be same as our our set parameters.
also if you fit the same thing without setting parameters in the code, we get different parameters.

Your initial parameters are:

root [0]    TF1 *fn2 = new TF1("fn2","4*x*x -2*x + 5" , -10 , 10);

For instance, at 0.2 you get:

root [1] fn2->Eval(0.2)
(double) 4.7600000

As you see that does not correspond to your plot. Minuit adjusted the parameter so they fit the data … that is the idea of the fitting.

1 Like

I would like to add that by setting the parameters you do not hold them fixed you just initialize them for that point for your fit.

1 Like

ahh now I get it , thanks.