Krieg, M. wrote: > > Hi Roots, > > I have the following problem concerning TGraph and the Linear Algebra > package: > > I want to plot several lineplots in a single graph using the TGraph class. > All plots use the same x-values stored in a float pointer *x but have (of > course) different y-values. The y-values are stored in a Matrix nK(i,j) of > the TMatrix class, each line of the Matrix corresponds to the y-values of > one plot. > Now the problem is, that TGraph needs 2 float pointers pointing at the x and > y values of the plot. So if I want to use TGraph I have to set float > pointers pointing on each line of the TMatrix Object. > I would like to know how one does that with a real good programming style > using the linear algebra package of ROOT! Has anyone an idea? > > Thanks a lot in advance! > Martina A possible solution is illustrated in the example below Rene Brun // macro gramat.C. Using matrix and graphs { gROOT->Reset(); const Int_t ngraphs = 10; const Int_t npoints = 15; Float_t a[ngraphs] = {0.2,0.3,0.42,0.48,0.62,0.71,0.91,1.03,1.14,1.35}; Float_t b[ngraphs] = {1,2,3,4,5,6,7,8,9,10}; Float_t x[npoints] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; TCanvas *c1 = new TCanvas("c1","test Matrix and Graphs"); c1->SetGrid(); c1->DrawFrame(0,0,16,32); TMatrix mat(npoints,ngraphs); for (Int_t gr=0;gr<ngraphs;gr++) { for (Int_t point=0;point<npoints;point++) { mat(point,gr) = b[gr] + a[gr]*x[point] + gRandom->Gaus(0,0.3); } TGraph *graph = new TGraph(npoints,x,&mat(0,gr)); graph->SetMarkerStyle(20+gr); graph->Fit("pol1","q0"); graph->Draw("p"); } mat.Print(); }
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:31 MET