Mtx Class Template Reference

Class template supports matrix calculations. More...

#include <Mtx.h>

Inherits Base.

Inheritance diagram for Mtx:

Inheritance graph
[legend]
List of all members.

Public Types

 COLUMN_DATA
 ROW_DATA = 0
 TOTAL_DATA
enum  VTYPE { ROW_DATA = 0, COLUMN_DATA, TOTAL_DATA, VTYPE_CNT }
 VTYPE_CNT

Public Member Functions

aType absolute (void) const
aType average (void) const
aType * copyArray (aType *array) const
aType determinant (void) const throw (MtxErr)
int getCount (enum Mtx< aType >::VTYPE vType) const
aType high (void) const
aType low (void) const
 Mtx (void)
 Mtx (const Mtx< aType > &mt)
 Mtx (aType var)
 Mtx (const aType *array, int nRows, int nCols)
Mtx< aType > operator * (aType scalar) const
Mtx< aType > operator * (const Mtx< aType > &mt) const
const Mtx< aType > operator *= (aType scalar)
 operator const aType * (void) const
 operator const aType *const * (void) const
Mtx< aType > operator! (void) const throw (MtxErr)
bool operator!= (const Mtx< aType > &mt) const
Mtx< aType > operator+ (const Mtx< aType > &mt) const
Mtx< aType > operator+ (void) const
Mtx< aType > operator+= (const Mtx< aType > &mt)
Mtx< aType > operator- (const Mtx< aType > &mt) const
Mtx< aType > operator- (void) const
const Mtx< aType > operator-= (const Mtx< aType > &mt)
Mtx< aType > operator/ (aType scalar) const
const Mtx< aType > operator/= (aType scalar)
const Mtx< aType > operator= (aType x)
const Mtx< aType > operator= (const Mtx< aType > &mt)
bool operator== (const Mtx< aType > &mt) const
Mtx< aType > operator~ (void) const
 ~Mtx (void)

Static Public Attributes

static const int DEF_PRINT_WIDTH = 14

Friends

template<typename bType>
bType fabs (const Mtx< bType > &mt)
template<typename bType>
Mtx< bType > operator * (bType scalar, const Mtx< bType > &mt)
template<typename bType>
std::ostream & operator<< (std::ostream &ostr, const Mtx< bType > &mt)

Detailed Description

template<typename aType>
class calc::Mtx< aType >

Class template supports matrix calculations.

This class template implements mathematical operations of two-dimensional matrices using <aType> variable declarations.

See the cited References to obtain more information on the mathematical theory applied here.

Author
efgeorge
Date
2006/07/18 01:45:34
Revision
1.2
Examples:

example_Intp.txt, and example_Mtx.txt.


Member Enumeration Documentation

enum VTYPE

Enumeration indicates the error index of a thrown calc::MtxErr object.

Enumerator:
ROW_DATA  index of the variable for the matrix row count
COLUMN_DATA  index of the variable for the matrix column count
TOTAL_DATA  index of the variable for the matrix total data count
VTYPE_CNT  error index count


Constructor & Destructor Documentation

Mtx ( const aType *  array,
int  nRows,
int  nCols 
)

Constructor initializes a matrix object with matrix data.

Parameters:
array a pointer to a matrix valued array
nRows row count of the matrix array
nCols column count of the matrix array
Remarks:
The specified array dimensions nRows and nCols must be greater than zero.

Mtx ( aType  var  ) 

Constructor initializes a matrix object with a single value.

Parameters:
var value to store in 1 by 1 dimension matrix
Remarks:
Theses matrix dimensions may change when added to other matrices.

Mtx ( const Mtx< aType > &  mt  ) 

Copy constructor initializes a matrix object from the specified existing matrix object.

Parameters:
mt a reference to a matrix object

Mtx ( void   ) 

Constructor initializes a matrix object with no matrix data.

~Mtx ( void   ) 

Destructor frees allocated memory.


Member Function Documentation

aType absolute ( void   )  const

Function relates a finds the average of absolute values of the matrix.

Returns:
the average absolute value of the matrix cells
If the matrix is uninitialized, the value zero is returned.

aType average ( void   )  const

Function returns the average value of all values stored in the matrix object.

Returns:
average matrix value
If the matrix is uninitialized, the value zero is returned.

aType * copyArray ( aType *  array  )  const

Function copies the object's matrix array to the specified pointer.

Parameters:
array a pointer to a copy of the matrix array values
Returns:
the value of the pointer array
Remarks:
  • The number of values in the array equals the matrix row count times the matrix column count (see Mtx::getCount()).
  • If the object is not initialized, a null pointer is returned.

aType determinant ( void   )  const throw (MtxErr)

Function returns the determinant of a matrix object. The matrix object must contain a square matrix.

Returns:
determinant value
Exceptions:
MtxErr type of object thrown
Remarks:
  • A returned value of zero indicates that the matrix is singular, or that the matrix is not square.
  • This function uses LU decomposition with partial pivoting to calculate the result.

int getCount ( enum Mtx< aType >::VTYPE  vType  )  const

Function returns variable count information pertaining to matrix dimensions.

Parameters:
vType variable index indentifying the type of data
Returns:
the matrix dimension count property of the object
Remarks:
  • Valid variable values should be above 0.
  • If the object is not initialized, -1 is returned.
  • If the object does not have the variable identified by vType, -1 is returned.

aType high ( void   )  const

Function returns the highest value stored in the matrix object.

Returns:
highest matrix value
If the matrix is uninitialized, the value zero is returned.

aType low ( void   )  const

Function returns the lowest value stored in the matrix object.

Returns:
lowest matrix value
If the matrix is uninitialized, the value zero is returned.

Mtx<aType> operator * ( aType  scalar  )  const

Function overloads the multiplication operator *. The function multiplies the specified matrix object by the specified scalar.

Parameters:
scalar a value to multiply by
Returns:
the product of the matrix and scalar
Remarks:
If the product of the matrix and scalar can not be calculated, an uninitialized matrix is returned.

calc::Mtx< aType > operator * ( const Mtx< aType > &  mt  )  const

Function overloads the multiplication operator *. The function finds the product of a matrix object times the specified matrix object.

Parameters:
mt a matrix object to be multiplied by
Returns:
the product of two matrices
Remarks:
  • The column count of the first matrix must be equal to the row count of the second matrix.
  • If the product of the matrices can not be calculated, an uninitialized matrix is returned.

const Mtx<aType> operator *= ( aType  scalar  ) 

Function overloads the multiplication assignment operator *=. The function multiplies the matrix object by the specified scalar.

Parameters:
scalar a value to multiply by
Returns:
the product of a matrix and scalar
Remarks:
If the product of the matrix and scalar can not be calculated, an uninitialized matrix is returned.

operator const aType * ( void   )  const

Conversion function returns a pointer to the matrix array of values of the matrix object.

Returns:
a pointer to the matrix data
Remarks:
  • The number of values in the array equals the matrix row count times the matrix column count (see Mtx::getCount()).
  • In the referenced memory block, array data is arranged first by column, then by row.
Note:
For conversion reference of a matrix object mt, the object is cast as: const aType *mt;

operator const aType *const * ( void   )  const

Conversion function returns a pointer to an array of row pointers that point to an array of column values in the matrix array of the matrix object.

Returns:
a pointer to the matrix data
Remarks:
  • The number of values in the array equals the matrix row count times the matrix column count (see Mtx::getCount()).
  • If an object initialization error occurred, a null pointer is returned.
Note:
For conversion reference of a matrix object mt, the object is cast as: const aType *const *mt;

calc::Mtx< aType > operator! ( void   )  const throw (MtxErr)

Function overloads the logical negation operator !. The function finds the inverse of a matrix object. The matrix object must contain a square matrix.

Returns:
the inverse of a square matrix
Remarks:
  • If the inverse of the matrix can not be calculated, an uninitialized matrix is returned.
  • This function uses Gauss elimination with full pivoting to calculate the results.
Exceptions:
MtxErr type of object thrown

bool operator!= ( const Mtx< aType > &  mt  )  const

Function overloads the inequality operator !=. The function compares the dimensions and values of two matrices.

Parameters:
mt a matrix object to be compared
Returns:
status flag
  • false (the matrices are equivalent)
  • true (the matrices are not equivalent)
Remarks:
  • The row count and column count of the two matrices must be equal.
  • Corresponding values in each matrix location must be equal.
  • If either matrix object is uninitialized then the value true is returned.

Mtx<aType> operator+ ( const Mtx< aType > &  mt  )  const

Function overloads the addition operator +. The function finds the sum of two matrices.

Parameters:
mt a matrix object to be added
Returns:
the sum of two matrices
Remarks:
  • The row count and column count of the two matrices must be equal.
  • If the sum of the matrices can not be calculated, an uninitialized matrix is returned.

Mtx<aType> operator+ ( void   )  const

Function overloads the addition operator +. The function returns a copy of the matrix.

Returns:
a copy of the matrix
Remarks:
If a copy of the matrix can not be made, an uninitialized matrix is returned.

Mtx<aType> operator+= ( const Mtx< aType > &  mt  ) 

Function overloads the addition assignment operator +=. The function finds the sum of two matrices and stores the results.

Parameters:
mt a matrix object to be added
Returns:
the sum of two matrices
Remarks:
  • The row count and column count of the two matrices must be equal.
  • If the sum of the matrices can not be calculated, an uninitialized matrix is returned.

Mtx<aType> operator- ( const Mtx< aType > &  mt  )  const

Function overloads the subtraction operator -. The function finds the difference between two matrices.

Parameters:
mt a matrix object to be subtracted
Returns:
the difference between two matrices
Remarks:
  • The row count and column count of the two matrices must be equal.
  • If the difference between the matrices can not be calculated, an uninitialized matrix is returned.

Mtx<aType> operator- ( void   )  const

Function overloads the subtraction operator -. The function finds the negative of a matrix.

Returns:
the negative of a matrix
Remarks:
If the negative of the matrix can not be calculated, an uninitialized matrix is returned.

const Mtx<aType> operator-= ( const Mtx< aType > &  mt  ) 

Function overloads the subtraction assignment operator -=. The function finds the difference between two matrices and stores the results.

Parameters:
mt a matrix object to be subtracted
Returns:
the difference between two matrices
Remarks:
  • The row count and column count of the two matrices must be equal.
  • If the difference between the matrices can not be calculated, an uninitialized matrix is returned.

Mtx<aType> operator/ ( aType  scalar  )  const

Function overloads the division operator /. The function multiplies the specified matrix object by the specified scalar reciprocal.

Parameters:
scalar a value to reciprocate and multiply by
Returns:
the product of the matrix and scalar reciprocal
Remarks:
If the product of the matrix and scalar reciprocal can not be calculated, an uninitialized matrix is returned.

const Mtx<aType> operator/= ( aType  scalar  ) 

Function overloads the division assignment operator /=. The function multiplies the matrix object by the reciprocal of the specified scalar.

Parameters:
scalar a value to multiply by
Returns:
the product of the matrix and scalar reciprocal
Remarks:
If the multiplication of the matrix by scalar reciprocal can not be calculated, an uninitialized matrix is returned.

const calc::Mtx< aType > operator= ( aType  x  ) 

Function overloads the assignment operator =. The function fills the existing matrix object with a single value x.

Parameters:
x a single value to be copied
Returns:
a matrix whose entries are filled with the single value x

const calc::Mtx< aType > operator= ( const Mtx< aType > &  mt  ) 

Function overloads the assignment operator =. The function copies the matrix object to an existing matrix.

Parameters:
mt a matrix object to be copied
Returns:
the copy of a matrix

bool operator== ( const Mtx< aType > &  mt  )  const

Function overloads the equality operator ==. The function compares the dimensions and values of two matrices.

Parameters:
mt a matrix object to be compared
Returns:
status flag
  • false (the matrices are not equivalent)
  • true (the matrices are equivalent)
Remarks:
  • The row count and column count of the two matrices must be equal.
  • Corresponding values in each matrix location must be equal.
  • If either matrix object is uninitialized then the value false is returned.

calc::Mtx< aType > operator~ ( void   )  const

Function overloads the bitwise negation operator ~. The function finds the transpose of a matrix object.

Returns:
the transpose of a matrix
Remarks:
If the transpose of the matrix can not be calculated, an uninitialized matrix is returned.


Friends And Related Function Documentation

bType fabs ( const Mtx< bType > &  mt  )  [friend]

Function overloads the <cmath> library function std::fabs(). The function relates a matrix magnitude value with the sum of absolute values of the matrix.

Parameters:
mt a reference matrix object to find the magnitude of
Returns:
the average absolute value of the matrix cells
If the matrix is uninitialized, the value zero is returned.

Mtx<bType> operator * ( bType  scalar,
const Mtx< bType > &  mt 
) [friend]

Function overloads the multiplication operator *. The function multiplies the specified scalar times the specified matrix object.

Parameters:
scalar a value to multiply by
mt a matrix object to be multiplied by
Returns:
the product of the matrix and scalar
Remarks:
If the product of the matrix and scalar can not be calculated, an uninitialized matrix is returned.

std::ostream& operator<< ( std::ostream &  ostr,
const Mtx< bType > &  mt 
) [friend]

Function overloads the bitwise left shift operator <<. The function prints the specified matrix to the specified stream.

Parameters:
ostr a reference to a stream
mt a matrix object
Returns:
the stream
Remarks:
If the matrix object contains incorrect data, the text "--Matrix object not initialized--" is printed.


Member Data Documentation

const int DEF_PRINT_WIDTH = 14 [static]

code format text formatting real number field width


The documentation for this class was generated from the following files:
Generated on Wed Jul 19 09:24:13 2006 for CalcLib by  doxygen 1.4.7