Previous: 15.1 Matrices
Up: 15.1 Matrices
Next: 15.1.2 Matrix Operations: Sums and Products
Previous Page: 15.1 Matrices
Next Page: 15.1.2 Matrix Operations: Sums and Products

15.1.1 Matrix Operations: Transforms

The first operation we will implement is the transformation of a vector X by a matrix A into a vector Y.

In other words, given the values of coefficients and the variables on the left hand side, find the values on the right hand side of the equations. Such linear transformation of a set of values is a common phenomenon in many practical applications such as electronic circuits, mechanical systems, chemical combinations, economic models, interactive relationships, and so forth.

If matrix has rows and columns, the algorithm for the equation is:

y[i] = a[i][0]*x[0] + a[i][1]*x[1] +...+ a[i][c-1]*x[c-1]
This is applied for all the rows from to . Translating this algorithm into C code, Figure 15.2 shows the function mapvector() that uses to map (i.e. transform) vector into vector .

With these utility functions in had, we can now write a driver program that reads a matrix and then transforms vectors until a zero vector is entered. The code is shown in Figure 15.3.

The program declares all array ranges of size MAX and uses the function getrc() to read the number of rows and columns in the matrix. It then reads and prints the transform matrix of the specified size. Then, the program reads vectors until a zero vector is entered, and for each vector maps it by mapvector() into a new vector which is printed. The function getrc() shown in Figure 15.4 and is included in file matutil.c.

The source files mat.c and matutil.c are compiled and linked and tested producing the following sample session:



Previous: 15.1 Matrices
Up: 15.1 Matrices
Next: 15.1.2 Matrix Operations: Sums and Products
Previous Page: 15.1 Matrices
Next Page: 15.1.2 Matrix Operations: Sums and Products

tep@wiliki.eng.hawaii.edu
Sat Sep 3 07:27:41 HST 1994