A good answer might be:


Matrices as Data Types

Here is a scheme for matrix data types. To create a matrix type, fill each blank with one of the choices.

    2                row
    1                column
 ______ dimensional _______ matrix

For example "3 dimensional column matrix", or "4 dimensional row matrix". In a programming language, you might declare a type for each of the matrix types. For example, in C:

typedef double colMatrix2[2];
typedef double colMatrix3[3];

typedef double rowMatrix2[2];
typedef double rowMatrix3[3];

Then you would write an equality-testing function for each type:

int equalCM2( colMatrix2 x, colMatrix2 y )
  return x[0] == y[0] && x[1] == y[1] ;

int equalCM3( colMatrix3 x, colMatrix3 y )
  return x[0] == y[0] && x[1] == y[1] && x[2] == y[2];


This gets awfully tedious, so usually you create a more general data type and hope that the user will keep row matrices and column matrices straight without help from the compiler. An elegant solution is to use object-oriented programming.

Since for us vectors will always be represented with column matrices, we will use only a few types.


Are the following two column matrices equal?

( 2, -1 )T
( 2.0, -1.0 )T