How to to Create and Fill a Matrix ?
Several decision have to be made:
- Float or double precision matrix. In the first case you will use the TMatrixF class family, in the latter case the TMatrixD one.
- The matrix type: general, symmetric or sparse.
- The matrix size and the index range.
For example a double-precision general matrix whose row index runs from -2 to 5 and column index from -5 to 10 is created through:
TMatrixD a(-2,5,-5,-10);
TMatrixD a(7,15);
- Referencing row/column combination (irow,icol) for matrix a as a[irow][icol] or a(irow,icol).
- Copying an array. This can be either through the constructor or through SetMatrixArray.
- Using an array or matrix through the Use function. Here, no data is copied.
An important issue in the linear algebra package is that matrices should have the same shape before they can be copied through an assignment. For instance:
TMatrixD b(2,3); TMatrixD a(4,4); b.ResizeTo(a); b = a;