# Fitting linear y=ax+b, covarianc from a and b

Hi!
I’d like to know covariance from a and b.
If you run a program, you get a fiited linear equation.
y=ax+b
a=p0 b=p1
absoultely, you see a graph in your screen.
p0, p1 average, standard deviation

gre2->ROOT::Fit::FitResult()

I’d like to know how to deal a function, ROOT::Fit::FitResult()
I am a beginner.
I am looking forward to your help.
thanks you.

{
gStyle->SetOptFit(1111);
Int_t m = 9;
Float_t logE[m];
Float_t logEffi[m];
Float_t elogEffi[m];
Float_t j[m] = {352.05,609.35,1120.44,1238.32,1764.58,463.15,727.38,795.00,911.27};
Float_t k[m] = {8.59E-02,5.89E-02,3.88E-02,3.62E-02,2.84E-02,4.77E-02,4.09E-02,3.97E-02,3.79E-02};
Float_t n[m] = {8.62E-04,6.04E-04,1.12E-03,2.82E-03,8.64E-04,1.85E-03,1.11E-03,1.45E-03,3.86E-04};

for(m =0; m < 9; m++ )
{ logE[m] = TMath::Log(j[m]);
logEffi[m] = TMath::Log(k[m]);
// elogEffi[m] = n[m]*logEffi[m];
elogEffi[m] = n[m]/k[m];
cout << logE[m] << " " << logEffi[m] << " " << elogEffi[m] << endl;
}
TCanvas *myc = new TCanvas(“myc”,“Fitting linear function”);
myc->SetFillColor(42);
myc->SetGrid();
// TGraph gre3 = new TGraph(m,logE,logEffi);
// gre3->Draw("a
");

TGraphErrors gre2 = new TGraphErrors(m,logE,logEffi,0,elogEffi);
gre2->SetTitle(“Linear Fitting of U238 and Th232”);
gre2->Draw("E1A
");
//Fit the graph with the predefined “pol1” function
gre2->Fit(“pol1”);
gre2->ROOT::Fit::FitResult();

} Hi,

here attached is your macro, corrected for some C++ errors, which retrieves and print the covariance matrix after fitting

Best Regards

Lorenzo
test.C (1.29 KB)