Good morning,
Please I am trying to understand how TMatrixes work. I have a code but I get errors. I want to be able to put data in my TMATRIX and read the data. I would be glad if I get assistant here. Thank you very much. I have the following errors.
"
home/harriet/fair_install/ATTPCROOTv2/build/macro6.C:79:6: error: no matching member function for call to ‘Use’
A_1.Use(Matrix_A);
~~^
/home/harriet/fair_install/FairSoft_apr22/Build/root/include/TMatrixT.h:130:35: note: candidate function not viable: no known conversion from ‘Double_t [4]’ to ‘TMatrixT &’ for 1st argument
TMatrixT &Use (TMatrixT &a);
^
/home/harriet/fair_install/FairSoft_apr22/Build/root/include/TMatrixT.h:131:35: note: candidate function not viable: no known conversion from ‘Double_t [4]’ to ‘const TMatrixT’ for 1st argument
const TMatrixT &Use (const TMatrixT &a) const;
^
/home/harriet/fair_install/FairSoft_apr22/Build/root/include/TMatrixT.h:128:35: note: candidate function not viable: requires 3 arguments, but 1 was provided
TMatrixT &Use (Int_t nrows,Int_t ncols,Element *data);
^
/home/harriet/fair_install/FairSoft_apr22/Build/root/include/TMatrixT.h:129:35: note: candidate function not viable: requires 3 arguments, but 1 was provided
const TMatrixT &Use (Int_t nrows,Int_t ncols,const Element *data) const;
^
/home/harriet/fair_install/FairSoft_apr22/Build/root/include/TMatrixT.h:124:35: note: candidate function not viable: requires 5 arguments, but 1 was provided
TMatrixT &Use (Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb,Element *data);
^
/home/harriet/fair_install/FairSoft_apr22/Build/root/include/TMatrixT.h:125:35: note: candidate function not viable: requires 5 arguments, but 1 was provided
const TMatrixT &Use (Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb,const Element *data) const
^
In file included from input_line_8:1:
/home/harriet/fair_install/ATTPCROOTv2/build/macro6.C:96:24: error: use of undeclared identifier ‘A_1’
const Int_t *rIndex = A_1.GetRowIndexArray();
^
/home/harriet/fair_install/ATTPCROOTv2/build/macro6.C:97:24: error: use of undeclared identifier ‘A_1’
const Int_t *cIndex = A_1.GetColIndexArray();
^
/home/harriet/fair_install/ATTPCROOTv2/build/macro6.C:98:26: error: use of undeclared identifier ‘A_1’
const Double_t *pData = A_1.GetMatrixArray();
^
/home/harriet/fair_install/ATTPCROOTv2/build/macro6.C:99:2: error: expected unqualified-id
for (Int_t irow = 0; irow < A_1.GetNrows(); irow++) {
^
/home/harriet/fair_install/ATTPCROOTv2/build/macro6.C:127:1: error: extraneous closing brace (‘}’)
}
^
This is my code .
void macro6 () {
TCanvas *c1 = new TCanvas("c1", "Radial", 500,600);
// KG= KALMAN GAIN , E_Est = ERROR IN ESTIMATE ,E_Mea = ERROR IN MEASUREMENT,EST_t = CURRENT ESTIMATE,EST_t-1 = PREVIOUS ESTIMATE,MEA MEASUREMENT;
Int_t n =5;
Double_t alpha,beta;
alpha = 0.8;
beta = 0.5;
// using TMATRICES FROM CERN.
//DEfine all matrices
TMatrixD A_1(2,2);
TMatrixD B_1(2,1);
TMatrixD X_1(2,1);
TMatrixD Y_1(2,1);
TMatrixD H_1(2,2);
TMatrixD R_1(2,2);
TMatrixD C_1(2,2);
TMatrixD P_1(2,2);
//Filling the matrixes.
TArrayD data(4);
for (Int_t i= 0; i < 4; i++) {
const Int_t ir = i/2;
const Int_t ic = i%2;
data[i] = 1./(ir+ic);
}
// A_1.SetMatrixArray(data.GetArray());
Double_t C_E[n], E_Est[n],E_CE[n],E_Mea,KG[n],q,mn[n];
Double_t x[n],dt,w,y[n],ay,v[n];
Double_t X[2][1],Matrix_1[2][1],Matrix_2[2][1],transpose_A[2][2],P[2][2];
Double_t dx,dv,Matrix_3[2][2],transpose_H[2][2],Matrix_4[2][2],Matrix_5[2][2];
Double_t add[2][2],K_G[2][2],Y[2][1];
//initial values.
dx = 20.0; // meters.
dv = 5; //m/s.
w = 0.0;
x[0] = 4000.0; // Units in meters.
v[0] = 280.0; // Units in meter/seconds.
//ax= 2.0; //in m/sec².
dt = 1.0;
C_E[0] = 10; // unit in m.
Double_t z[10] = {49.95,49.967,50.10,50.106,49.992,49.819,49.933,50.007,50.023,49.99}; // units in m.
Double_t Matrix_A[4] = {1,0,dt,1};
A_1.Use(Matrix_A);
//To use all these in my TMatrix.
Double_t Matrix_B[2][1] = {0.5*TMath::Power(dt,2),dt};
Double_t Matrix_X[2][1] = {x[0],v[0]};
Double_t Matrix_Y[2][1] ;
Double_t Matrix_H[2][2] = {{1,0},{0,1}} ;
Double_t Matrix_R[2][2] ={{625,0},{0,36}};
Double_t Matrix_C[2][2] = {{1,0},{0,1}};
Double_t ax[2][1] = {2.0,0.0};
Double_t Matrix_P[2][2] = {{TMath::Power(dx,2),0.0},{0.0,TMath::Power(dv,2)}} ; // generated errors.
}
//for printing the TMatrix.
const Int_t *rIndex = A_1.GetRowIndexArray();
const Int_t *cIndex = A_1.GetColIndexArray();
const Double_t *pData = A_1.GetMatrixArray();
for (Int_t irow = 0; irow < A_1.GetNrows(); irow++) {
const Int_t sIndex = rIndex[irow];
const Int_t eIndex = rIndex[irow+1];
for (Int_t index = sIndex; index < eIndex; index++) {
const Int_t icol = cIndex[index];
const Double_t data = pData[index];
printf("data(%d,%d) = %.4en",irow+A_1.GetfRowLwb(),
icol+A_1.GetColLwb(),data);
}
}
// return 0;
/*
TGraph *gr1 = new TGraph(n,mn,z);
TGraph *gr2 = new TGraphErrors(n,mn,C_E);
// create a multigraph and draw it
TMultiGraph *mg = new TMultiGraph();
mg->Add(gr1);
mg->Add(gr2);
mg->Draw("ALP");
*/
// TGraph *gr1 = new TGraph(n,mn,C_E);
// gr1->GetXaxis()->SetTitle("mn");
/// gr1->GetYaxis()->SetTitle("temperature");
// gr1->Draw("ALP");
}