Matrix Handling Classes

  1. The General Class
  2. Full Matrices
  3. Storage Schemes:
  4. Solving Linear Systems:
  5. Deriving a New Class

The General Class

Header File: tmatrix.h

This is the class from which the various types of matrices are derived. In the TMatrix class we define the behaviour to be implemented by derived classes, and the TMatrix class implements flags that informs, for example, if a matrix was decomposed and the decomposition method used (we need this information because the result of a matrix decomposition is stored at the matrix ifself.
Every algebraic operation between matrices will return a full matrix . It is sufficient for almost all cases and releases implementation of many particular cases.

Several submatrix operations are avaliable, such as putting a submatrix inside a matrix, copying a submatrix to a matrix and to sum matrices and submatrices. They can be used for all type of matrices, using a subclass for this purpose, the TBlock class.

Several algorithms were implemented as virtual methods. This implies that every subclass of TMatrix has a set of decomposition algorithms. In most derived classes these methods are redefined to improve efficiency.

Return to Main Menu


Full Matrices

Header File: tfullmat.h

The TFMatrix class implements Full Matrices. This class is useful for matrices that have no special property (symmetry, sparsity), or to store results of operations involving several types of matrices. See testing to have an idea of the use of TFMatrix . The TFMatrix class is the only class which has a defined storage pattern. The elements of TFMatrix are stored column - wise to increase compatibility with FORTRAN libraries and BLAS routines.

Return to Main Menu


Symmetric Matrices

Header File: tsimmat.h

The TSimMatrix class implements Symmetric Matrices. From this class are derived several subclasses, as on TMatrix class:

  1. TSFMatrix: symmetric full matrices (See testing );
  2. TSBMatrix: symmetric band matrices;
  3. TSSpMatrix: symmetric sparse matrices;

Symmetric matrix objects will store n*(n+1)/2 components when the matrix is square of order n.

Return to Main Menu


Banded Matrices

Header Files: tbndmat.h and tsbndmat.h

The TFBMatrix class implements Banded Matrices, that are frequently used to solve small finite-difference and finite element problems. Symmetric Banded Matrices are implemented by the TSBMatrix class. See testing to have an idea of the use of TFBMatrix .

Return to Main Menu


Skyline Matrices

Header File: tskylmat.h

Skyline Matrices are implemented at TskylMatrix class. These matrices are symmetric and its main feature is the storage: at each column, only the elements from diagonal to the highest (lowest) row are stored:


E X A M P L E 

   2.3    0  2.1    0    0	        2.3     2.1
     0    0    2  1.1    0       is          0    2  1.1
   2.1    2   10    3    1     stored	     	 10    3    1
     0  1.1    3    1   13       as:		       1   13
     0    0    1   13  4.2  			          4.2

Decomposition algorithms and iterative methods are redefined to improve efficiency. See testing for more details.

Return to Main Menu


Block Matrices

Header File: tblock.h

An object of TBlock class isn't a matrix, but a division of a square matrix in blocks, providing another way to work with this matrix without modifying it.
A TBlock object associated with a matrix M is defined by the blocks at the diagonal and its dimensions, whose sum must match with M. A block or submatrix may be an matrix of any dimension compatible with M. The blocks at the diagonal must be square, however. The following matrix division was defined by three blocks (numbered from 0 to 2) with dimensions 2x2, 3x3 and 2x2 respectively:


E X A M P L E

	[ * *  * * *  * * ]		The blocks at the diagonal 
 	[ * *  * * *  * * ]		determine the position of
 	[		  ]		any matrix block:
	[ * *  * * *  * * ]
	[ * *  * * *  * * ]		[ (0,0) (0,1)  (0,2) ]
 	[ * *  * * *  * * ]		[ (1,0) (1,1)  (1,2) ]
	[		  ]		[ (2,0) (2,1)  (2,2) ]
	[ * *  * * *  * * ]
	[ * *  * * *  * * ]

There are some more situations on testing.

Return to Main Menu


Sparse Matrices

Header File: tespmat.h and tsespmat.h

The TSpMatrix (TSSpMatrix) class implements Sparse (Symmetric Sparse) Matrices. Sparse matrix objects store only nonzero elements. See testing to have an idea of the use of TSpMatrix. The sparse matrix classes redefine the decomposition algorithms and iterative methods to improve efficiency.

Return to Main Menu


Linear Systems: Direct Methods

These methods perform a factorization of the matrix and solve the system using substitution algorithms. There are trhee methods available:

The use of LU decomposition is demonstrated within the Full Matrices example, while Choleski and LDLt decompositions are demonstrated within the Simmetric Matrices examples.

Return to Main Menu


Linear Systems: Iterative Methods

Iterative methods require arguments related to the tolerance for the residual, and number of iteractions, but don't change the original matrix. The following methods are available:

They are demonstrated within the TMatrixSolver example (next section).

The dynanmic iterative methods ( CG, GRMES ) are implemented within the Template package, which is available on Netlib. Some minimal changes were made to their header files to improve numeric efficiency.

Return to Main Menu


TMatrixSolver Class

Header File: tsolve.h

This is an especial class that takes care of all the process of solving a linear system:

See testing to have an idea of the use of TMatrixSolver.

Return to Main Menu


Deriving a New Class

The user may derive his own classes. Three methods need to be implemented within the derived classes:

virtual void PutVal(int row, int col, REAL value)
PutVal sets the element (row,col) equal to value
virtual REAL &GetVal(int row, int col).
GetVal returns a reference for the element (row,col).
virtual void Mult(TFMatrix &matin, TFMatrix &matout, int opt)
Mult multiplies the current matrix (or the transpose of the current matrix, if opt = 1) by matin,storing the result in matout.

The users may choose to define both PutVal and GetVal, define Mult or both. The first choice uses the fact that Mult is already implemented on TMatrix class. The second choice allows to derive matrix classes whose storage pattern does not allow to modify or access individual elements (e.g. element wise storage form). We choose the last one when the structure of the new matrices sugests improve methods of multiplication. In cases where PutVal and/or GetVal are not defined, a call to any of these methods will/can result in a program halt.

Return to Main Menu