mathkit  1.5
 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 square () const
 Test if the matrix is a square matrix. More...
 
bool symmetric () const
 Test if the matrix is symmetric. 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 13 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 18 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 23 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 27 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 32 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 37 of file Matrix.cpp.

Table mathkit::Matrix::getData ( ) const

Get matrix data.

Returns
The matrix data.

Definition at line 54 of file Matrix.cpp.

Dimen mathkit::Matrix::dimen ( ) const

Get matrix dimension.

Returns
The dimension of the matrix.

Definition at line 58 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 62 of file Matrix.cpp.

int mathkit::Matrix::nrow ( ) const

The number of rows.

Returns
The number of rows.

Definition at line 68 of file Matrix.cpp.

int mathkit::Matrix::ncol ( ) const

The number of columns.

Returns
The number of columns.

Definition at line 72 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 76 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 85 of file Matrix.cpp.

bool mathkit::Matrix::symmetric ( ) const

Test if the matrix is symmetric.

Returns
True if the matrix is symmetric else false.

Definition at line 89 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 94 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 100 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 104 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 108 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 112 of file Matrix.cpp.

Matrix mathkit::Matrix::transpose ( ) const

Transpose matrix.

Returns
The transposed matrix.

Definition at line 126 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 132 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 162 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 171 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 185 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 189 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 193 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 200 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 207 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 216 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 220 of file Matrix.cpp.


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