[ROOT] Polynom fit

From: Yuriy Prokazov (yuriypro@narod.ru)
Date: Mon Apr 01 2002 - 02:11:13 MEST


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