Stores a dense matrix. More...
#include <Morpheus_Matrix.h>
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. | |
Stores a dense matrix.
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
Definition at line 25 of file Morpheus_Matrix.h.
| 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.
| [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.
| double & Morpheus::Matrix::operator() | ( | const int | row, | |
| const int | col | |||
| ) |
Accesses a single entry of the matrix.
| [in] | row | Row |
| [out] | col | Column |
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
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.
Computes a matrix-vector multiplication.
| [in] | X | vector to be multiplied |
| [out] | Y | result of multiplication |
Definition at line 47 of file Morpheus_Matrix.cpp.
Computes a matrix-matrix multiplication.
| [in] | X | matrix to be multiplied |
| [out] | Y | result of multiplication |
Definition at line 64 of file Morpheus_Matrix.cpp.
| bool Morpheus::Matrix::isSymmetric | ( | ) | const |
Determines whether the matrix is symmetric.
Definition at line 85 of file Morpheus_Matrix.cpp.
| bool Morpheus::Matrix::isUpperTriangular | ( | ) | const |
Determines whether the matrix is upper triangular.
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
| [in] | m | The matrix to be compared |
| [in] | tol | The tolerance of the comparison |
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.
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.
1.6.1