Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Matrices

Multi-dimensional arrays of floating-point numbers arise in many different scientific computations. Such arrays are usually called matrices . Mathematicians have studied the properties of matrices for many years and have developed an extensive repertoire of operations on matrices. In this section we consider two-dimensional matrices of doubles and examine the implementation of simple, matrix multiplication.

The preceding sections show that there are many possible ways to implement matrices. In order to separate interface from implementation, we define the abstract Matrix base class shown in Program gif.

   program3104
Program: Matrix abstract class.

This interface defines an indexer (with get and put accessors) and methods for some of the elementary operations on matrices such as computing the transpose  of a matrix (Transpose), adding  matrices (Plus), and multiplying  matrices (Times). In addition, the addition and multiplication operators + and * are overloaded for use with Matrix instances.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.