Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

3.2 Defining Matrices

Once we understand vectors, the next most important abstraction in linear algebra is the concept of a linear mapping from one vector space to another. Since we are concerned only with vectors of finite dimension, such a mapping can always be represented using a matrix of coefficients. If x is a vector from one space, and y is a vector from another, we can represent a linear mapping from x to y as y=Ax, where A is a matrix, and Ax is an inner product. Often, the matrix A has some special structure; for example, it may be banded or symmetric.

LAPACK.h++ has classes for many different matrix types. Each matrix type has a similar interface, so if you learn one, learning the others is easy. To give you a feel for using a matrix type, here is a simple example using a tridiagonal matrix class:

//1The first line declares the class FloatTriDiagMat as a new C++ type by including the Rogue Wave header file ftrdgmat.h. A variable of type FloatTriDiagMat represents a tridiagonal matrix of floating point numbers. A tridiagonal matrix is a matrix where all the entries are 0, except for the entries on the main diagonal, and the entries immediately above and below the main diagonal.
//2This line defines T to be an uninitialized 6 x 6 tridiagonal matrix; the next line sets all of its entries to 0.
//3Here we use the diagonal function to set the entire main diagonal to 2. The next two lines set the other two nonzero diagonals to 1 and 3.
//4In this line, we use subscripting to access a particular element of the matrix and change it. The matrix is set up as follows: