mathkit  2.0
 All Classes Namespaces Functions Variables Typedefs
Public Member Functions | List of all members
mathkit::Matrix Class Reference

Matrix class. More...

#include <Matrix.hpp>

Public Member Functions

 Matrix ()
 Default constructor.
 
 Matrix (const Table &data)
 Constructor with initial data. More...
 
 Matrix (Dimen dimen, double val=0)
 Constructor with a specific initial value. More...
 
 Matrix (const Vector &data, Dimen dimen, bool byrow=true)
 Constructor with initial data. More...
 
void setData (const Table &data)
 Set matrix data. More...
 
void setData (Dimen dimen, double val=0)
 Set Matrix data with a specific value. More...
 
void setData (const Vector &data, Dimen dimen, bool byrow=true)
 Set matrix data. More...
 
Table getData () const
 Get matrix data. More...
 
Dimen dimen () const
 Get matrix dimension. More...
 
bool dimen (Dimen dimen)
 Set matrix dimension. More...
 
int nrow () const
 The number of rows. More...
 
int ncol () const
 The number of columns. More...
 
Matrix round (int ndec=4) const
 Round every element to specific decimal digits. More...
 
bool eq (const Matrix &mat, const Epsilon &eps=Epsilon()) const
 Test whether two matrices are equal to the specific precision. More...
 
bool square () const
 Test if the matrix is a square matrix. More...
 
bool symmetric (const Epsilon &eps=Epsilon()) const
 Test if the matrix is symmetric. More...
 
bool uptri (const Epsilon &eps=Epsilon()) const
 Test if the matrix is upper triangular. More...
 
bool lowtri (const Epsilon &eps=Epsilon()) const
 Test if the matrix is lower triangular. More...
 
bool diag (const Epsilon &eps=Epsilon()) const
 Test if the matrix is diagonal. More...
 
Vector getRow (int m) const
 Get a row data. More...
 
Vector getCol (int n) const
 Get a column data. More...
 
void setRow (int m, const Vector &row)
 Set a row data. More...
 
void setCol (int n, const Vector &col)
 Set a column data. More...
 
void exchange (int i, int j, bool row=true)
 Exchange two rows or two columns. More...
 
Matrix transpose () const
 Transpose matrix. More...
 
int rank (const Epsilon &eps=Epsilon()) const
 Rank of matrix. More...
 
Matrix submat (int frow, int lrow, int fcol, int lcol)
 Submatrix. More...
 
Matrix resid (int i, int j) const
 Residual matrix. More...
 
double & operator() (int m, int n)
 Access a specific element of the matrix. More...
 
double operator() (int m, int n) const
 Access a specific element of the matrix (read only). More...
 
Matrix operator+ (const Matrix &mat) const
 Matrix addition. More...
 
Matrix operator- (const Matrix &mat) const
 Matrix subtraction. More...
 
Matrix operator* (const Matrix &mat) const
 Matrix multiplication. More...
 
bool operator== (const Matrix &mat) const
 Matrix equality. More...
 
bool operator!= (const Matrix &mat) const
 Matrix inequality. More...
 

Detailed Description

Matrix class.

The row and column indices start from zero.

Definition at line 15 of file Matrix.hpp.

Constructor & Destructor Documentation

mathkit::Matrix::Matrix ( const Table data)

Constructor with initial data.

Parameters
dataThe initial data.

Definition at line 15 of file Matrix.cpp.

mathkit::Matrix::Matrix ( Dimen  dimen,
double  val = 0 
)

Constructor with a specific initial value.

Parameters
dimenThe dimension of the matrix.
valThe specific initial value.

Definition at line 20 of file Matrix.cpp.

mathkit::Matrix::Matrix ( const Vector data,
Dimen  dimen,
bool  byrow = true 
)

Constructor with initial data.

Parameters
dataA vector contains the initial data.
dimenThe dimension of the matrix.
byrowThe initial data is in row major or column major form.

Definition at line 25 of file Matrix.cpp.

Member Function Documentation

void mathkit::Matrix::setData ( const Table data)

Set matrix data.

Parameters
dataThe new matrix data.

Definition at line 29 of file Matrix.cpp.

void mathkit::Matrix::setData ( Dimen  dimen,
double  val = 0 
)

Set Matrix data with a specific value.

Parameters
dimenThe dimension of the matrix.
valThe specific value.

Definition at line 34 of file Matrix.cpp.

void mathkit::Matrix::setData ( const Vector data,
Dimen  dimen,
bool  byrow = true 
)

Set matrix data.

Parameters
dataA vector contains the new data.
dimenThe dimension of the matrix.
byrowThe new data is in row major or column major form.

Definition at line 39 of file Matrix.cpp.

Table mathkit::Matrix::getData ( ) const

Get matrix data.

Returns
The matrix data.

Definition at line 56 of file Matrix.cpp.

Dimen mathkit::Matrix::dimen ( ) const

Get matrix dimension.

Returns
The dimension of the matrix.

Definition at line 60 of file Matrix.cpp.

bool mathkit::Matrix::dimen ( Dimen  dimen)

Set matrix dimension.

The dimension could be set only when the matrix data is empty. Else this operation would fail.
This method should only be used when the matrix is contructed by default contructor and need to load data using stream extraction operator (>>).

Parameters
dimenThe dimension.
Returns
Whether the operation succeed.

Definition at line 64 of file Matrix.cpp.

int mathkit::Matrix::nrow ( ) const

The number of rows.

Returns
The number of rows.

Definition at line 70 of file Matrix.cpp.

int mathkit::Matrix::ncol ( ) const

The number of columns.

Returns
The number of columns.

Definition at line 74 of file Matrix.cpp.

Matrix mathkit::Matrix::round ( int  ndec = 4) const

Round every element to specific decimal digits.

Parameters
ndecThe number of decimal digits.
Returns
A matrix with each element rounded to specific decimal digits.

Definition at line 78 of file Matrix.cpp.

bool mathkit::Matrix::eq ( const Matrix mat,
const Epsilon eps = Epsilon() 
) const

Test whether two matrices are equal to the specific precision.

Parameters
matThe another matrix.
epsAn Epsilon functor to control accurary.
Returns
True if the matrices are equal else false.

Definition at line 87 of file Matrix.cpp.

bool mathkit::Matrix::square ( ) const

Test if the matrix is a square matrix.

Returns
True if the matrix is square else false.

Definition at line 96 of file Matrix.cpp.

bool mathkit::Matrix::symmetric ( const Epsilon eps = Epsilon()) const

Test if the matrix is symmetric.

Parameters
epsAn Epsilon functor to control accurary.
Returns
True if the matrix is symmetric else false.

Definition at line 100 of file Matrix.cpp.

bool mathkit::Matrix::uptri ( const Epsilon eps = Epsilon()) const

Test if the matrix is upper triangular.

Parameters
epsAn Epsilon functor to test zero elements.
Returns
True if the matrix is upper triangular else false.

Definition at line 105 of file Matrix.cpp.

bool mathkit::Matrix::lowtri ( const Epsilon eps = Epsilon()) const

Test if the matrix is lower triangular.

Parameters
epsAn Epsilon functor to test zero elements.
Returns
True if the matrix is lower triangular else false.

Definition at line 114 of file Matrix.cpp.

bool mathkit::Matrix::diag ( const Epsilon eps = Epsilon()) const

Test if the matrix is diagonal.

Parameters
epsAn Epsilon functor to test zero elements.
Returns
True if the matrix is diagonal else false.

Definition at line 123 of file Matrix.cpp.

Vector mathkit::Matrix::getRow ( int  m) const

Get a row data.

Parameters
mThe row index (start from zero).
Returns
A vector contains the specific row data.

Definition at line 127 of file Matrix.cpp.

Vector mathkit::Matrix::getCol ( int  n) const

Get a column data.

Parameters
nThe column index (start from zero).
Returns
A vector contains the specific column data.

Definition at line 133 of file Matrix.cpp.

void mathkit::Matrix::setRow ( int  m,
const Vector row 
)

Set a row data.

Parameters
mThe row index (start from zero).
rowThe new row data.

Definition at line 137 of file Matrix.cpp.

void mathkit::Matrix::setCol ( int  n,
const Vector col 
)

Set a column data.

Parameters
nThe column index (start from zero).
colThe new column data.

Definition at line 141 of file Matrix.cpp.

void mathkit::Matrix::exchange ( int  i,
int  j,
bool  row = true 
)

Exchange two rows or two columns.

Parameters
iThe index of first row/column to exchange.
jThe index of second row/column to exchange.
rowWhich stuff to exchange (row or column).

Definition at line 145 of file Matrix.cpp.

Matrix mathkit::Matrix::transpose ( ) const

Transpose matrix.

Returns
The transposed matrix.

Definition at line 159 of file Matrix.cpp.

int mathkit::Matrix::rank ( const Epsilon eps = Epsilon()) const

Rank of matrix.

Parameters
epsAn Epsilon functor to test zero elements.
Returns
The rank of the matrix.

Definition at line 165 of file Matrix.cpp.

Matrix mathkit::Matrix::submat ( int  frow,
int  lrow,
int  fcol,
int  lcol 
)

Submatrix.

Parameters
frowThe first row index.
lrowThe last row index.
fcolThe first column index.
lcolThe last column index.
Returns
The submatrix.

Definition at line 195 of file Matrix.cpp.

Matrix mathkit::Matrix::resid ( int  i,
int  j 
) const

Residual matrix.

Parameters
iThe row index (zero based).
jThe column index (zero based).
Returns
A matrix with the ith row and jth column excluded.

Definition at line 204 of file Matrix.cpp.

double & mathkit::Matrix::operator() ( int  m,
int  n 
)

Access a specific element of the matrix.

Parameters
mThe row index (start from zero).
nThe column index (start from zero).
Returns
A reference of the specific element.

Definition at line 218 of file Matrix.cpp.

double mathkit::Matrix::operator() ( int  m,
int  n 
) const

Access a specific element of the matrix (read only).

Parameters
mThe row index (start from zero).
nThe column index (start from zero).
Returns
The specific element.

Definition at line 222 of file Matrix.cpp.

Matrix mathkit::Matrix::operator+ ( const Matrix mat) const

Matrix addition.

Parameters
matThe right matrix operand.
Returns
A matrix contains the result of addition.

Definition at line 226 of file Matrix.cpp.

Matrix mathkit::Matrix::operator- ( const Matrix mat) const

Matrix subtraction.

Parameters
matThe right matrix operand.
Returns
A matrix contains the result of subtraction.

Definition at line 233 of file Matrix.cpp.

Matrix mathkit::Matrix::operator* ( const Matrix mat) const

Matrix multiplication.

Parameters
matThe right matrix operand.
Returns
A matrix contains the result of multiplication.

Definition at line 240 of file Matrix.cpp.

bool mathkit::Matrix::operator== ( const Matrix mat) const

Matrix equality.

Parameters
matThe right matrix operand.
Returns
Whether the matrices are equal.

Definition at line 249 of file Matrix.cpp.

bool mathkit::Matrix::operator!= ( const Matrix mat) const

Matrix inequality.

Parameters
matThe right matrix operand.
Returns
Whether the matrices are inequal.

Definition at line 253 of file Matrix.cpp.


The documentation for this class was generated from the following files: