Class CAMdoubleMatrix Reference

Include File : cammva.h


A class for a matrix of values of type double and whose member functions are operations on matrices as well as matrix/matrix operations.

 The class CAMmvaGraphics provides graphical output routines that accept CAMdoubleMatrix arguments. Specific functions for CAMdoubleMatrix are described in "Graphics Functions for CAMdoubleMatrix".

Chris Anderson © UCLA 8/18/97


Constructors
CAMdoubleMatrix M; M is a null matrix.
CAMdoubleMatrix M(m,n); M is a matrix of size m by n with indices starting at (1,1)..
CAMdoubleMatrix M(_(m1,m2),_(n1,n2)); M is a matrix whose indices run from (m1,n1) to (m2,n2).
_(m1,m2) and _(m2,n2) are CAMrange objects. e
CAMdoubleMatrix M(T); M is a copy of matrix T.

Often, when programming with CAMdoubleMatrix objects one desires to change the structure of an existing object. The initialize function allows one to re-initialize an existing object to have a different structure. The initialization process discards any data previously associated with the object. The new data values are initialized to 0.

Initialize

M.initialize(); M is initialized to a null matrix.
M.initialize(m,n); M is initialized to a matrix of size m by n with indices starting at (1,1)..
M.initialize(_(m1,m2),_(n1,n2)); M is initialized to a matrix whose indices run from (m1,n1) to (m2,n2).
_(m1,m2) and _(m2,n2) are CAMrange objects. e
M.initialize(T); M is initialized as a copy of matrix T.


Unary and Binary Operations

= Assignment. M = T; assigns the values in the matrix T to M.
+ Addition. M = T + S; assigns the sum of T + S to M.
- Subtraction. M = T - S; assigns the difference of T - S to M.
* Multiplication. M= S*T assigns the CAMdoubleMatrix M the product of the CAMdoubleMatrix S times the CAMdoubleMatrix T.
/ M = S/T assigns to M the quantity S -1 * T. If x and v are CAMdoubleVectors, then x = M/b assigns to x the values in M -1 * b. (The application of the inverse is computed using Gaussian Elimination).
~ Transpose. M = ~T; assigns to M the transpose of T.
-() Negation. M = -T; assigns to M the opposite of the values in T.
+= Incremental addition. M+=T; is equivalent to M = M+ T;
-= Incremental subtraction . M-=T is equivalent to M = M - Y;
*= Incremental multiplication. M*=T is equivalent to M =M*T;
/= Incremental division. M/=T is equivalent to M =M/T;
<< Matrix output. cout << M; outputs the matrix to the output stream cout.
>> Matrix input. cin >> M; inputs the matrix from the input stream cin.

The operators in the table above are applicable whenever the expression in which they are contained makes mathematical sense, i.e. the dimensions and the type of the object are correct. 

Scaler multiplication and division of matrix objects is allowed (except in the case of a one element matrix, then the assignment, addition, or subtraction with a scaler using the operators -, +, and = results in an error. The member functions setToValue(), plusValue(), minusValue() are used for such operations.)


Matrix Element Access

M(i,j); The element of the matrix M whose index is (i,j).
M(i,_); The ith row of the matrix M.
M(_,j); The jth column of the matrix M.
M(_(i1,i2),_(j1,j2)); The sub-matrix of M whose indices run from (i1,j1) to (i2,j2).

Each of the expressions in the previous table can occur on the left as well as the right hand side of an assignment statement. So, for example, to add the second and the fourth row of a matrix M to its first row, one could use the statement

M(1,_) = M(2,_) + M(4,_);

There is one syntax construction in C++ which does not work when dealing with sub-matrices - ``multiple assignment'' statements of the form A = B = C. For example, the statement

A = B(_(2,3),_(2,3)) = C;

will cause the compiler to issue an error and stop. This is an artifact of our particular implementation of these classes.


Matrix Structure Access

n = M[1].getIndexCount(); n (a long) is assigned the number of rows of M.
n = M[2].getIndexCount(); n (a long) is assigned the number of columns of M.
n = M[1].getIndexBase(); n (a long) is assigned the row index starting value.
n = M[1].getIndexBound() ; n (a long) is assigned the row index starting value.
n = M[2].getIndexBase(); n (a long) is assigned the column index starting value.
n = M[2].getIndexBound(); n (a long) is assigned the column index ending value.
M[1].setIndexBase(n); The starting row index of M is set to the long n
M[2].setIndexBase(n); The starting column index of M is set to the long n
d = M.getDataPointer(); The pointer d (of type double*) is set to the address of the first element of the data in M. The data is stored by columns (FORTRAN storage convention).


Matrix Utility Functions

d = M.max(), A double d is assigned the maximum of the elements of the M.
d = M.min(); A double d is assigned the minimum of the elements of M.
d = M.maxAbs(); A double d is assigned the maximum of the absolute value of the elements of M.
d = M.minAbs(); A double d is assigned the minimum of the absolute value of the elements of CAMdoubleMatrix M.
M.setToValue(d); Every element of M is assigned the value the double d.
R=M.plusValue(d); R is set to the matrix obtained by adding d to every element of M.
R=M.minusValue(d); R is set to the matrix obtained by subtracting d from every element of M.
M = CAMdoubleMatrix::identity(n); M is assigned an n by n identity matrix.