Fit function is not right?

I have a data set. I tried to fit with Root, but it was not successful. However, when I process this data with Excel, there is not any problems. Could you help me, please?
Here is my code

#include <TF1.h>
#include <TGraph.h>
#include <TMarker.h>
#include <TAxis.h>

void heso()
{
    TGraph *g0 = new TGraph("factor.txt");
    g0->SetLineColor(kRed);
    g0->SetMarkerStyle(8);
    g0->SetMarkerColor(kRed);
    g0->SetMarkerSize(1);
    g0->Draw("ACP");
    g0->GetYaxis()->SetRangeUser(0, 300000);

    TF1 *fit = new TF1("fit", "[0]*(x^[1])", 5, 30);
    fit->SetLineColor(kBlue);
    g0->Fit("fit");

}

factor.txt (616 Bytes)


Try with:

TF1 *fit = new TF1("fit", "[0]+(x^[1])", 5, 30);

Thank you. It is a good different choice. But I want to fit the data set by function [0]*(x^[1])
Here is a result obtained by Excel and the fit function is good for the data set.

Then maybe @moneta can help you

fit->SetParameters(13., 3.) /* good initial values */; g0->Fit(fit);

1 Like

Thanks a lot. It works fine. Could you explain what the reason here is?