GenLib2::Matrix< T > Class Template Reference

Matrix class. More...

#include <matrix.h>

List of all members.

Public Member Functions

 ~Matrix ()
 destructor
constructors.
 Matrix ()
 constructor without size
 Matrix (int m, int n, const T &val=T(0))
 constructor with size and initilize with value
 Matrix (int m, int n, const T *v)
 constructor, initialize with array
 Matrix (int m, const T &val=T(0))
 constructor of row vector and initilize with zeros
 Matrix (int m, const T *v)
 constructor of row vector, initialize with array
 Matrix (const Matrix &A)
 copy constructor
methods.
Matrixoperator= (const Matrix &A)
 copy operator
Matrixcopy (int rl, int cl, const Matrix &A)
 copy sub-matrix A into *this matrix
Matrixnewsize (int m, int n=1)
 new size Change the matrix size when the number of columns and rows are changed.
Matrixclear ()
 set all elements to zero (obsolete method replaced by null-method)
Matrixnull ()
 set all elements to zero
void set_diagonal ()
 set diagonal elements to 1 (and don't change off-diagonal elements)
void identity (T val=T(1))
 set identity matrix.
Matrixset_all (const T &val)
 set all elements to value
void get_col (int c, Matrix &col)
void make_upper_symmetric ()
 make a square matrix symmetric (by mirroring the upper part)
void make_lower_symmetric ()
 make a square matrix symmetric (by mirroring the lower part)
member data access.
int rows () const
 number of rows
int cols () const
 number of columns
int size () const
 number of matrix elements
bool is_data () const
 data check
bool is_row () const
 data check
T & elem (int i, int j) const
 get matrix element function using (i,j) indexing
void elem (int i, int j, T val)
 set matrix element function using (i,j) indexing
T & operator() (int i, int j)
 get matrix element using (i,j) indexing
const T & operator() (int i, int j) const
 get matrix element using (i,j) indexing
T & operator() (int i)
 get matrix element of row-vector using (i) indexing
const T & operator() (int i) const
 get matrix element of row-vector using (i) indexing
T * row (int i) const
 get pointer to a row
I/O methods.
void read (std::istream &is)
 read matrix
void print (ostream &os) const
 print matrix
void print_symb (ostream &os, char zero=' ', char nozero='*') const
 print symbolic
void print_pbm (ostream &os) const
 print in PBM-format
composite assignment operators.
Matrixoperator*= (T s)
 multiplication with a scalar
Matrixoperator/= (T s)
 division by a scalar
these are routines taken from Numerical Recipes in C.

They are only to be used for REAL, SYMMETRIC matrices (square matrices, of course).

void tred2 (Matrix &d, Matrix &e)
 householder reduction (numerical recipes, page 373) householder reduction (to a tridiagonal matrix) for a real, symmetric matrix (*this) is replaced by the orthogonal matrix Q d returns the diagonal elements e returns the off-diagonal elements with e(0)=0
bool tqli (Matrix &d, Matrix &e, int maxIter=30)
 QL algorithm with implicit shifts (numerical recipes, page 380) d and e are the elements of a real, symmetric, tridiagonal matrix (d=diagonal, e=off-diagonal elements, e(0) arbitrary).
bool eigensystem (Matrix &eigen_vals, Matrix &eigen_vecs)
 Determines eigenvalues and eigenvectors f the (*this) matrix for a real, symmetric matrix RETURNS: (the value of *this is preserved) eigenVals: Nx1 vector of all eigenvalues eigenVects: NxN matrix of all eigenvectors, written as columns (i-th column eigenVects(*,i) corresponds to eigenvalue eigenVals(i)).

Protected Member Functions

internal helper functions.
void allocate (int m, int n)
 allocate memory
void free ()
 free memory
void copy (const T *v)
 copy array
void set (const T &val)
 set all elements to value

Protected Attributes

int _m
 matrix dimension, number of rows
int _n
 matrix dimension, number of columns
T * _data
 matrix elements
T ** _row
 row-pointer


Detailed Description

template<class T>
class GenLib2::Matrix< T >

Matrix class.

General matrix class.

Author:
Dirk Stallmann

Member Function Documentation

template<class T>
Matrix< T > & GenLib2::Matrix< T >::newsize ( int  m,
int  n = 1 
) [inline]

new size Change the matrix size when the number of columns and rows are changed.

Attention, the elements are not initilized! Therefore use the null-method to set all elements to zero.

References GenLib2::Matrix< T >::_m, GenLib2::Matrix< T >::_n, GenLib2::Matrix< T >::allocate(), and GenLib2::Matrix< T >::free().

Referenced by GenLib2::Matrix< T >::operator=().

template<class T>
void GenLib2::Matrix< T >::identity ( val = T(1)  )  [inline]

set identity matrix.

Set diagonal elements to value and non-diagonal elements will be cleared.

References GenLib2::Matrix< T >::_m, GenLib2::Matrix< T >::_n, and GenLib2::Matrix< T >::_row.

template<class T>
bool GenLib2::Matrix< T >::tqli ( Matrix< T > &  d,
Matrix< T > &  e,
int  maxIter = 30 
) [inline]

QL algorithm with implicit shifts (numerical recipes, page 380) d and e are the elements of a real, symmetric, tridiagonal matrix (d=diagonal, e=off-diagonal elements, e(0) arbitrary).

(*this) is either the identity matrix in which case the eigenvectors of the tridiagonal matrix are returned or the matrix as returned by tred2. Then, the eigenvectors of the original 'A'-matrix are returned. maxIter is the maximum allowed number of iterations (if present)

RETURNS: d(i) : eigenvalue i e : destroyed (*this): k-th column contains normalized eigenvector corresponding to d(i) All results are only valid if the routine returns TRUE

References GenLib2::Matrix< T >::_m, GenLib2::Matrix< T >::_n, and GenLib2::Matrix< T >::rows().

template<class T>
bool GenLib2::Matrix< T >::eigensystem ( Matrix< T > &  eigen_vals,
Matrix< T > &  eigen_vecs 
) [inline]

Determines eigenvalues and eigenvectors f the (*this) matrix for a real, symmetric matrix RETURNS: (the value of *this is preserved) eigenVals: Nx1 vector of all eigenvalues eigenVects: NxN matrix of all eigenvectors, written as columns (i-th column eigenVects(*,i) corresponds to eigenvalue eigenVals(i)).

Result only valid if the routine returns TRUE

References GenLib2::Matrix< T >::_m, GenLib2::Matrix< T >::_n, GenLib2::Matrix< T >::cols(), GenLib2::Matrix< T >::rows(), and GenLib2::Matrix< T >::tred2().


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

Generated on Wed Aug 6 15:46:43 2008 by  doxygen 1.5.5