File: readme.txt
Autor: Nathan Toner
Modified: July 28, 2011
/*****************************************************************************
CLmatrix.h
*****************************************************************************/
Header file for CLmatrix class. For a program in which you want to use this class, move
this file and CLmatrix.cpp to the present working directory and:
#include "CLmatrix.h"
Then compile the main program along with CLmatrix.cpp. Then in the code, you can define
objets of class CLmatrix, and perform operations between them (discussed below).
For compiling a code that uses the CLmatrix class, execute the following (or
similar):
g++ -Wall -o [exec_name] [source_name].cpp CLmatrix.cpp
Where [exec_name] is the desired name of the executable, and [source_name] is
the name of your C++ source code.
/*****************************************************************************
CLmatrix.cpp
*****************************************************************************/
Includes the code defining all member functions of class CLmatrix, as well as operations
between members of this class. Operations currently include addition (+),
subtraction (-), multiplication (*), assignment (=) and transposition (!=).
Objects of class CLmatrix contain the following:
int n - number of rows in the matrix
int m - number of columns in the matrix
double** mat - values of the matrix stored in matrix form ( mat[n][m] )
double* vect - values of the matrix 'mat' stored in a vector in column-major order
/*****************************************************************************
Objects of class CLmatrix may be created with the following syntax:
*****************************************************************************/
CLmatrix object;
- null constructor for class CLmatrix
- sets n = m = 1, and mat = trans = vect = 0
CLmatrix object ( n, m );
- specify the rows and columns of the matrix as integer values n and m
- allocates memory for mat, trans, and vect of appropriate size
- sets all elements of the object equal to zero (0).
CLmatrix object ( n, m, values );
- specify the rows and columns of the matrix as integer values n and m
- specify the values of the matrix as vector (double*) 'values' in column-major
order
- An example of column-major order:
vector[2 * 2] = {1, 2, 3, 4} is equivalent to matrix[2][2] = {{1, 2}, {3, 4}}.
The first is the vector in column-major order containing all the elements of
the matrix.
CLmatrix object ( n, m, matrix );
- specify the rows and columns of the matrix as integer values n and m
- specify the values of the matrix as 'matrix' (double**)
- as of July 28, 2011 (v1.0) this option does not work.
/*****************************************************************************
The following operators are defined between objects of class CLmatrix:
*****************************************************************************/
Addition (+)
- between two matrices of the same size (rows and columns). The matrices are then
added element by element.
- between a matrix and a vector with the same number of rows. The vector is then
added to each column of the matrix.
- gives an error and exits program if dimensions are incompatable.
Subtraction (-)
- between two matrices of the same size (rows and columns). The matrices are then
subtracted element by element.
- between a matrix and a vector with the same number of rows. The vector is then
subtracted from each column of the matrix.
- gives an error and exits program if dimensions are incompatable.
Multiplication (*)
- here the number of rows of the right-hand argument must equal the number of
columns of the left-hand argument.
- result will have the same number of rows as the left-hand argument, and same
number of columns as the right-hand argument.
- gives an error and exits program if dimensions are incompatable.
Assignment (=)
- sets the left-hand argument equal to the right-hand argument
- does so by copying the values of n and m, then allocating memory for the new
object, and then assigning values from the 'vect' member of the right-hand
argument to the left-hand argument.
- gives an error and exits program self-assignment is detected ( a = a ).
- requires that the right-hand argument be an expression, not just an
object, e.g.:
'object1 = object2*object3' works, but
'object1 = object2' does not.
For the latter case, use 'object1.assign(object2.vect)' instead.
Transpose Assignment (!=)
- Sets the left-hand argument equal to the transpose of the right-hand
argument
- Does so by copying the values of n and m from the right-hand argument in to
the values of m and n respectively of the left-hand argument, and then
copying the transpose of the right-hand argument in to its 'vect' member.
It then assigns values from 'vect' to the left-hand argument.
- Allows for self-assignment.
/*****************************************************************************
The following member functions exist for objects of class CLmatrix:
*****************************************************************************/
printMat();
- prints the values stored in the matrix to the screen with a tag identifying
it as "mat".
- syntax is 'objectName.printMat();'
printTrans();
- similar to above but prints the transpose of the matrix with tag "trans =".
- syntax is 'objectName.printTrans();'
printVect();
- similar to above but prints the values in the matrix in a single vector in
column-major order with the tag "vect = (column-major order)".
- syntax is 'objectName.printVect();'
/*****************************************************************************
testMain.cpp
*****************************************************************************/
Contains a main function for testing the CLmatrix class (CLmatrix.cpp and CLmatrix.h
files). Must be compiled along with CLmatrix.cpp to use the CLmatrix class. Also must
have #include "CLmatrix.h" at the beginning of the file.
g++ -Wall -o testMat testMain.cpp CLmatrix.cpp