# Linear Fit Failed

Hello ROOTers,

I have 7 points and I wrote a program that allows me to graph them, then from Fit Panel I want to graph them. The code I wrote is as follows:

``````{
auto c4 = new TCanvas("Note","Retta di calibrazione",200,10,1400,600);
double x[] = {338.1-303.5, 340.4-303.5, 342.5-303.5, 345-303.5, 347.4-303.5, 349.8-303.5, 352-303.5};
double y[] = {5.00911e+00, 1.07664e+01, 2.58592e+01, 2.15048e+01, 3.04902e+01, 4.34195e+01, 5.14712e+01};
double ex[] = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
double ey[] = {4.36461e+00, 5.73364e+00, 3.96376e+00, 5.41579e+00, 8.09999e+00, 3.91632e+00, 3.96578e+00};
auto ge = new TGraphErrors(7, x, y, ex, ey);
ge->SetTitle("Retta di calibrazione");
ge->GetYaxis()->SetTitle("[1] [Canali]");
ge->Draw("ap");
``````

The points, except one, seem to lie on a straight line:
Note.pdf (13,6 KB)
yet if I do the fit using the formula [4]*x+[5] it fails, as visible:

``````TFitEditor::DoFit - using function PrevFitTMP  0x55cd040612d0
FCN=4.32032 FROM HESSE     STATUS=FAILED         11 CALLS         357 TOTAL
EDM=3.74884e-12    STRATEGY= 1  ERROR MATRIX UNCERTAINTY 100.0 per cent
EXT PARAMETER                APPROXIMATE        STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  p4           3.20664e+00   4.16915e-02   7.28745e-04  -3.38385e-05
2  p5          -1.05021e+02   1.75982e+00  -2.90538e-02  -6.22644e-07

``````

Why is this happening? I have used the program countless times and it has always done its job well.

`ge->Fit("pol1");`

BTW. You must “number” parameters of your formula starting from 0 (e.g. `"[0]*x+[1]"`) and you need to set “reasonable” initial values for all of them, before fitting.

In this case:

`````` FCN=4.32032 FROM MIGRAD    STATUS=CONVERGED      43 CALLS          44 TOTAL
EDM=4.26647e-12    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  p0          -1.05021e+02   1.47939e+01   1.98201e-03  -6.22643e-07
2  p1           3.20664e+00   3.50481e-01   4.69555e-05  -3.38214e-05

``````

It is the same but “converged”, i dont see any error matrix accurate.

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