---------- > From: Valery Fine <fine@mail.cern.ch> > To: Voropaev S.G. <voropaev@inp.nsk.su>; roottalk@hpsalo.cern.ch > Subject: Re: Fit x,y [2] > > > Hi, > > I investigate my problem. New example: > > > > float x[20], y[20]; > > for(int i=0; i<20; i++) {x[i]=(i+1)/21.0; y[i]=0.5*x[i]+0.2;}; > > c1 = new TCanvas("c1","proba"); > > TGraph *tg = new TGraph(20,x,y); > > tg->Draw("AP"); > > tg->Fit("pol1"); // All is OK. I see all my point and long line. > > > > for(int i=0; i<20; i++) {x[i]=gRandom->Rndm(1); y[i]=0.5*x[i]+0.2;}; > > delete tg; TGraph *tg = new TGraph(20,x,y); tg->Draw("AP"); > > tg->Fit("pol1"); > > > > Now I see all my point and very short line. The X range of line is > > 0.1-0.2! > > But did you see you the graphic view properly ? > You may say "yes" but I'll insist "no". That's because of the > shape of your function special function: 0.5*x + 0.2, Change your > function to something else and draw it and WITH APL options to > see the REAL its shape. (For example 0.5*x**2 + .2). No ask some > human (not computer) to fit that "by hand". I think the problem is in the invalid range of fit: float x[20],y[20]; for(int i=0; i<20; i++) {x[i]=gRandom->Rndm(1); y[i]=0.5*x[i]*x[i]+0.2;}; c1 = new TCanvas("c1","Fit"); TGraph *tg = new TGraph(20,x,y); TF1 *f1 = new TF1("f1","pol2"); tg->Draw("AP"); tg->Fit("f1","","AP"); // Fit range 0.1 - 0.2 ! f1->SetRange(0.2,1.0); tg->Fit("f1","R","AP"); // All is OK f1->SetRange(0.0,1.0); tg->Fit("f1","R","AP"); // All is OK Now, you can see that TGraph::Fit set invalid default fit range in case of unsorted x,y data. With best regards Voropaev S.G.
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:20 MET