Hi Yuriy,
When I moved the function TGraph::LeastSquareFit from protected to public,
I forgot to remove a dependency on two global variables gxfirst,gxlast.
I have now introduced a new version of TGraph.h,cxx in CVS.
This new version has new calling sequences for:
void InitExpo(Int_t first=0, Int_t last=0);
void InitGaus(Int_t first=0, Int_t last=0);
void InitPolynom(Int_t first=0, Int_t last=0);
void LeastSquareFit(Int_t m, Double_t *a, Int_t first=0, Int_t last=0);
I have tested that your example works correctly. If you use this new
version, replace your statement;
g->LeastSquareFit(i, 3, par );
by
g->LeastSquareFit(3, par );
Rene Brun
On Sun, 31 Mar 2002, Yuriy Prokazov wrote:
> Dear Rene,
> I've tried to use TGraph::LeastSquareFit() without success, probably I am
> doing something wrong. Here is the script and output. I tried ROOT versions
> 3.03/2 and 3.02/7 with the same result.
>
> Thank you, Yuriy.
>
> ------------------------------------------- Script -----------------------
> TCanvas *c;
> TGraph *g, gg;
> Double_t par[20];
>
> void pfit() {
> c = new TCanvas( "c1", "c1" );
> Double_t *px = new Double_t[10000];
> Double_t *py = new Double_t[10000];
> Int_t i;
> Double_t x;
> Double_t dx = 0.01;
> for( x=-5, i=0; i<1000; i++, x+=dx ) {
> px[i] = x; py[i] = x*x+2*x-1;
> }
> g = new TGraph( i, px, py );
> g->Draw("AP");
> g->LeastSquareFit( i, 3, par );
> printf( "%f\n", par[0] );
> printf( "%f\n", par[1] );
> printf( "%f\n", par[2] );
> delete px;
> delete py;
> }
> ------------------------------------------- Output -----------------------
> 14.000000
> 0.000000
> 0.000000
>
> while I expect 1, 2, -1.
>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:47 MET