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();
}