MATRIX.CPP

Description : Function definitions for matrix operations

Header files called upon : math.h, VECTOR.H , MATRIX.H . The specific statement 'extern "C" int exit(int);' exempts the need for the inclusion of stdlib.h

Class details are as follows:

Further class member definitions : Vector

Constructors (public)
Vector::Vector(const Vector &v)
Constructor to copy an already existing vector into a previously undeclared vector
eg Vector vec2(vec1);
NB1 vec2 is previously undeclared, vec1 already initialized
NB2 function is declared in VECTOR.H
Member functions (public)
Vector& Vector::operator= (const Vector& v)
Overloads '=' operator for vector assignment
eg vec1 = vec2;
NB function declared in VECTOR.H

ostream& operator << (ostream &os, Vector &v)
Overloads '<<' operator to write out a vector
eg cout << vec1;
NB function declared in VECTOR.H

Further class member definitions : Matrix

Constructors (public)
Matrix::Matrix(const Matrix &m) : nr(m.nr), nc(m.nc)
Constructor to copy an already existing matrix into a previously undeclared matrix
eg Matrix mat2(mat1);
NB1 mat2 is previously undeclared, mat1 already initialized
NB2 function declared in MATRIX.H
Member functions (public)
Vector Matrix::operator* (Vector &v) const
Overloads '*' operator foror pre-multiplication of a vector by a matrix
eg vec2 = mat1 * vec1;
NB function declared in MATRIX.H

Matrix Matrix::operator- (Vector &v) const
Subtraction of a vector from each row of a matrix
eg mat2 = mat1 - vec1;
NB function declared in MATRIX.H

void Matrix::eigens(int n, Vector &eval, Matrix &evec)
Derives 'n' eigenvalues and puts them in decreasing magnitude into specified vector, also derives corresponding eigenvectors and puts them in columns into specified (n x n) matrix
eg mat1.eigens(n,vec_eigenval,mat_eigenvect);
NB1 maximum value of n allowed for is 10
NB2 vec_eigenval is vector of returned eigenvalues
NB3 mat_eigenvect is matrix of returned eigenvectors
NB4 function declared in MATRIX.H

void Matrix::eigen(int mv, int n, float* a, float* r)
Calculates 'n' eigenvalues (mv = 0) or 'n' eigenvalues+eigenvectors (mv = 1)
NB1 'a' is a pointer to a 1D float array of size n*(n+1)/2 used for workspace and also returns eigenvalues, 'r' is a pointer to a 1D float array of size n*n and returns eigenvectors
NB2 'eigen' is called by the above member function 'eigens'
NB3 function declared in MATRIX.H

void Matrix::esort(int mv, int n, float* a, float* r)
Sorts eigenvalues (mv = 0) or eigenvalues+eigenvectors (mv = 1) in order of descending eigenvalue
NB1 arguments must be identical to those for the above member function 'eigen' which must be called first before calling 'esort'
NB2 'esort' is called by member function 'eigens'
NB3 function declared in MATRIX.H

Vector Matrix::colMean()
Returns the column mean of a matrix as a vector, in other words, the nth element of the vector is the mean of the values of the nth row in the matrix
eg vec1 = mat1.colMean(); if mat1 = (1.1 3.3) then vec1 = (2.2)
NB function declared in MATRIX.H

void Matrix::cholinv()
Inverts a matrix employing Cholesky decomposition
eg mat1.cholinv();
NB1 mat1 must be square matrix with positive determinant
NB2 function declared in MATRIX.H

Matrix operator * (const Matrix& m1, const Matrix& m2)
Overloads '*' operator for matrix multiplication
eg mat1 = mat2 * mat3;
NB function declared in MATRIX.H

Matrix operator & (const Matrix& m1, const Matrix& m2)
Overloads '&' operator to multiply a transpose of a matrix by another matrix
eg mat1 = mat2 & mat3;
NB1 the transpose of mat2 is used but mat2 itself is not affected
NB2 mat2 and mat3 must have same number of rows (errorchecked by function)
NB3 user will need to ensure that the (rows x columns) dimensions of mat1 are (mat2_columns x mat3_columns)
NB4 function declared in MATRIX.H

ostream& operator << (ostream &os, Matrix &m)
Overloads '<<' operator to write out a matrix
eg cout << mat1;
NB function declared in MATRIX.H

Further class member definitions : LtMatrix

As yet incomplete