Morpheus::Matrix Class Reference

Stores a dense matrix. More...

#include <Morpheus_Matrix.h>

List of all members.

Public Member Functions

Constructors and destructors



 Matrix (const int nrows, const int ncols)
 Constructor.
 ~Matrix ()
 Destructor.
Accessor functions



double & operator() (const int row, const int col)
 Accesses a single entry of the matrix.
int getNumRows () const
 Returns the number of rows.
int getNumCols () const
 Returns the number of columns.
int getNumEntries () const
 Returns the number of entries.
Multiplication routines



void multiply (const Vector &X, Vector &Y) const
 Computes a matrix-vector multiplication.
void multiply (const Matrix &X, Matrix &Y) const
 Computes a matrix-matrix multiplication.
Matrix property query methods



bool isSymmetric () const
 Determines whether the matrix is symmetric.
bool isUpperTriangular () const
 Determines whether the matrix is upper triangular.
bool approxEqual (const Matrix &m, const double tol) const
 Determines whether this matrix is approximately equal to another matrix.
Norms



double norm1 () const
 Maximum absolute column sum.
double normInf () const
 Maximum absolute row sum.
I/O functions



void print () const
 Prints matrix to console.

Private Attributes

int nrows_
 Number of rows.
int ncols_
 Number of columns.
double ** data_
 Pointer to raw data.

Detailed Description

Stores a dense matrix.

Todo:

Add a function for computing the Frobenius norm

Add a function for computing the 2-norm

Add a function for reading a matrix from a file

Examples:

Morpheus_Matrix_Tests.cpp.

Definition at line 25 of file Morpheus_Matrix.h.


Constructor & Destructor Documentation

Morpheus::Matrix::Matrix ( const int  nrows,
const int  ncols 
)

Constructor.

Allocates memory for a dense matrix. If either nrows or ncols is not positive, the program terminates.

Parameters:
[in] nrows Number of rows
[in] ncols Number of columns

Definition at line 15 of file Morpheus_Matrix.cpp.

Morpheus::Matrix::~Matrix (  ) 

Destructor.

Deallocates memory allocated in the constructor

Definition at line 31 of file Morpheus_Matrix.cpp.


Member Function Documentation

double & Morpheus::Matrix::operator() ( const int  row,
const int  col 
)

Accesses a single entry of the matrix.

Parameters:
[in] row Row
[out] col Column
Note:
This is 0-based, not 1-based indexing

Usage:

 Matrix m(4,3);
 m(0,0) = 1; m(0,1) = 0; m(0,2) = 0;
 m(1,0) = 0; m(1,1) = 1; m(1,2) = 0;
 m(2,0) = 0; m(2,1) = 0; m(2,2) = 1;
 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0;

creates the matrix
$\left[\begin{array}{rrr} 1&0&0\\0&1&0\\0&0&1\\0&0&0 \end{array}\right]$

Definition at line 41 of file Morpheus_Matrix.cpp.

int Morpheus::Matrix::getNumRows (  )  const

Returns the number of rows.

Definition at line 159 of file Morpheus_Matrix.cpp.

int Morpheus::Matrix::getNumCols (  )  const

Returns the number of columns.

Definition at line 165 of file Morpheus_Matrix.cpp.

int Morpheus::Matrix::getNumEntries (  )  const

Returns the number of entries.

Definition at line 171 of file Morpheus_Matrix.cpp.

void Morpheus::Matrix::multiply ( const Vector X,
Vector Y 
) const

Computes a matrix-vector multiplication.

Parameters:
[in] X vector to be multiplied
[out] Y result of multiplication
Note:
This function does not allocate memory for Y; it only fills in the values. The number of rows of the matrix must equal the number of entries in Y. The number of columns of the matrix must equal the number of entries in X. Otherwise, the program will terminate.
Todo:
Write a test for this function
Examples:
Morpheus_Matrix_Tests.cpp.

Definition at line 47 of file Morpheus_Matrix.cpp.

void Morpheus::Matrix::multiply ( const Matrix X,
Matrix Y 
) const

Computes a matrix-matrix multiplication.

Parameters:
[in] X matrix to be multiplied
[out] Y result of multiplication
Note:
This function does not allocate memory for Y; it only fills in the values. The number of rows of the calling matrix must equal the number of rows of Y. The number of columns of the calling matrix must equal the number of rows of X. X and Y must have the same number of columns. Otherwise, the program will terminate.

Definition at line 64 of file Morpheus_Matrix.cpp.

bool Morpheus::Matrix::isSymmetric (  )  const

Determines whether the matrix is symmetric.

Note:
The symmetry is not stored as a property of the matrix. Every time this function is called, it will perform the O(n^2) comparison of entries.
Examples:
Morpheus_Matrix_Tests.cpp.

Definition at line 85 of file Morpheus_Matrix.cpp.

bool Morpheus::Matrix::isUpperTriangular (  )  const

Determines whether the matrix is upper triangular.

Note:
This is not stored as a property of the matrix. Every time this function is called, it will perform the O(n^2) comparison of entries.
Examples:
Morpheus_Matrix_Tests.cpp.

Definition at line 103 of file Morpheus_Matrix.cpp.

bool Morpheus::Matrix::approxEqual ( const Matrix m,
const double  tol 
) const

Determines whether this matrix is approximately equal to another matrix.

Returns true if

  • this and m are the same size
  • this(r,c) == m(r,c) for all r, c
Parameters:
[in] m The matrix to be compared
[in] tol The tolerance of the comparison
Examples:
Morpheus_Matrix_Tests.cpp.

Definition at line 177 of file Morpheus_Matrix.cpp.

double Morpheus::Matrix::norm1 (  )  const

Maximum absolute column sum.

Definition at line 122 of file Morpheus_Matrix.cpp.

double Morpheus::Matrix::normInf (  )  const

Maximum absolute row sum.

Definition at line 141 of file Morpheus_Matrix.cpp.

void Morpheus::Matrix::print (  )  const

Prints matrix to console.

Example:
4x3 Matrix
1 0 0
0 1 0
0 0 1
0 0 0

Definition at line 194 of file Morpheus_Matrix.cpp.


Member Data Documentation

int Morpheus::Matrix::nrows_ [private]

Number of rows.

Definition at line 170 of file Morpheus_Matrix.h.

int Morpheus::Matrix::ncols_ [private]

Number of columns.

Definition at line 172 of file Morpheus_Matrix.h.

double** Morpheus::Matrix::data_ [private]

Pointer to raw data.

Definition at line 174 of file Morpheus_Matrix.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables

Generated on 2 Aug 2016 for Morpheus by  doxygen 1.6.1