Root fit

Hi I am trying to fit a user defined function to some data points. I plotted them using the class TGraph but can’t work out how to fit my function …
I have attached my macro
can you please tell me where I went wrong


#include “TH1.h”
#include “TF1.h”
#include “TLegend.h”
#include “TCanvas.h”
#include “math.h”

Double_t fitf(Double_t *x,Double_t *par) {

Double_t val;

val = par[1]*pow(x[0],par[2])+par[3];

return val;
}

void fitprob() {

Int_t x[13] = {20,30,50,70,100,200,300,500,700,1000,2000,3000,5000};

Int_t y[13] = {34,58,113,174,276,660,1096,2114,3343,5712,16335,30240,65654};

TGraph *gr1 = new TGraph(13,x,y);

gr1 -> Draw(“A*”);

TH1 *fitFcn = new TH1(“fitFcn”,fitf,20,2000,3);

fitFcn->SetNpx(500);
fitFcn->SetLineWidth(4);
fitFcn->SetLineColor(kMagenta);

fitFcn->SetParameters(0.4,1.4,1);
gr1->Fit(“fitFcn”);

}


[quote]can’t work out how to fit my function … [/quote]TH1 *fitFcn = new TH1("fitFcn",fitf,20,2000,3); // but this is histogram TF1 *fitFcn = new TF1("fitFcn",fitf,20,2000,3); // you need functionJan