Previous: 15 Engineering Programming Examples
Up: 15 Engineering Programming Examples
Next: 15.2 Complex Numbers
Previous Page: 15 Engineering Programming Examples
Next Page: 15.1.1 Matrix Operations: Transforms
We saw in Chapter that systems of
simultaneous linear algebraic equations can be represented
and manipulated using two dimensional arrays.
For example, a set of
equations in
unknowns:
Mathematically, such a system can be thought of in terms of a matrix
equation written in the form:
where
is a matrix, i.e. a two dimensional
array of coefficients
,
is a vector, i.e. a one dimensional array of elements
,
and
is also a vector,
.
In a matrix representation of algebraic equations,
the number of rows corresponds to the number of equations, and the number of
columns corresponds to the number of unknowns.
(In our case, the values of
range from
through
,
and those of
range from
through
).
When the number of rows and columns are equal,
the matrix is square, otherwise the matrix is rectangular.
Such a matrix equation may be viewed as a transformation of a
vector, , to another
vector,
, by matrix operator
.
Matrix formalism facilitates combinations of
transformations, deriving properties of transformations, as well as finding
solutions of equations.
In the next few sections, we will illustrate some useful matrix manipulations and begin to build our own library of utility functions for matrix operations. Many of the functions written can be used in a variety of programs; therefore, we will organize our code in several source files. The file matutil.c will contain all the functions we write for matrix manipulations. As usual, the prototypes for these functions are assumed to be in the file matutil.h.
In constructing our library, we first
implement basic input/output functions for matrices
and vectors: the function readmatrix() reads the elements of
a matrix into a two dimensional array, and
the function printmatrix() prints the matrix elements.
(These
functions are similar to the functions getcoeffs() and pr2adbl()
in Chapter , except
that the right hand side is not included in the matrix array).
Vectors are read
and printed by functions readvector() and printvector().
We assume the number
of rows and columns are passed as parameters, and that the
matrices are arrays of type double.
The basic I/O functions for
matrices and vectors and the requisite header files are straightforward
to develop, and are shown in Figure 15.1

These functions are quite simple. The number of rows and columns for the two dimensional arrays are passed as parameters, as are the sizes of the one dimensional arrays. The functions readmatrix() and readvector() return a cumulative sum of the input values. If desired, these sums may be used by the calling function to detect a matrix or a vector with all zero elements.