I want to plot error bars and fit the graph along with it. The code I have written is,
{
f = new TF1("fit", "[0]*x + [1]",0,5);
f -> SetParNames("Slope", "Interceptor");
double x[5]={2.68,4.73,0.415, 4.34, 4.73}, y[5] = {661.66, 1274.54,122.061, 1173.24, 1332.51}, xerr[5]= {0.119,0.10625, 0.10625, 0.204, 0.21675}, yerr[5]={0,0,0,0,0};
g = new TGraphErrors(5, x, y, xerr, yerr);
g -> Fit(fit, "R"); // Had also put f instead of fit and trying without "R" also but same graph showing
g->Draw(); // Also tried with "AP" , "A", "A*" but nothing happened
}
But there is still a problem remains. the fitting line did not show up on the graph.
please help me on it.
{
TF1 * f = new TF1("fit", "[0]*x + [1]",0,5);
gStyle -> SetOptFit(1);
f -> SetParNames("Slope", "Interceptor");
double x[5]={0.415,2.68,4.34,4.73,4.73}, y[5] = {122.061,661.66,1173.24,1274.54,1332.51}, xerr[5]= {0.10625,0.119,0.204,0.10625,0.21675}, yerr[5]={0,0,0,0,0};
TGraphErrors *g = new TGraphErrors(5, x, y, xerr, yerr);
g -> Fit(f);
g->Draw("A*");
}
but the output:
Warning in <Fit>: Abnormal termination of minimization.
FCN=0 FROM MIGRAD STATUS=FAILED 102 CALLS 103 TOTAL
EDM=44636 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 100.0 per cent
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 Slope 0.00000e+00 5.72655e-32 0.00000e+00 -3.68935e+33
2 Interceptor 0.00000e+00 1.41421e+00 -0.00000e+00 0.00000e+00
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1