Main Page | Class Hierarchy | Class List | File List | Class Members

PLib::Matrix< T > Class Template Reference

A templated matrix class with basic mathematical operators. More...

#include <matrix.h>

Inheritance diagram for PLib::Matrix< T >:

PLib::Basic2DArray< T > PLib::LUMatrix< T > PLib::MatrixImage< T > PLib::MatrixRT< T > List of all members.

Public Member Functions

 Matrix (const int r, const int c)
 Matrix (const Matrix< T > &M)
 Matrix (T *p, const int r, const int c)
Matrix< T > & operator= (const Matrix< T > &)
operator= (const T v)
void submatrix (int i, int j, Matrix< T > &)
void as (int rw, int cl, Matrix< T > &)
Matrix< T > get (int rw, int cl, int nr, int nc) const
Matrix< T > & operator+= (const Matrix< T > &)
Matrix< T > & operator-= (const Matrix< T > &)
Matrix< T > & operator+= (double d)
Matrix< T > & operator-= (double d)
Matrix< T > & operator *= (double d)
Matrix< T > & operator/= (double d)
Matrix< T > herm () const
Matrix< T > transpose () const
Matrix< T > flop () const
trace () const
double norm (void)
void diag (const T fv)
Vector< T > getDiag ()
void qSort ()
int read (char *filename)
int read (char *filename, int rows, int cols)
int write (char *filename)
int writeRaw (char *filename)

Friends

class LAPACK
Matrix< T > operator+ (const Matrix< T > &, const Matrix< T > &)
Matrix< T > operator- (const Matrix< T > &, const Matrix< T > &)
Matrix< T > operator * (const Matrix< T > &, const Matrix< T > &)
Matrix< T > operator * (const double, const Matrix< T > &)
Matrix< T > operator * (const Complex &, const Matrix< T > &)
Vector< T > operator * (const Matrix< T > &, const Vector< T > &)
int operator== (const Matrix< T > &, const Matrix< T > &)
int operator!= (const Matrix< T > &a, const Matrix< T > &b)

Detailed Description

template<class T>
class PLib::Matrix< T >

A templated matrix class with basic mathematical operators.

This is a matrix class which has basic mathematical operators and some routines for input/output.

Author:
Philippe Lavoie
Date:
4 Oct. 1996


Member Function Documentation

template<class T>
void PLib::Matrix< T >::as int  rw,
int  cl,
Matrix< T > &  a
 

copies a matrix into this matrix starting at index (rw,cl)

Parameters:
rw the row to insert the matrix at
cl the column to insert the matrix at
a the matrix to insert
Warning:
The matrix a must fit inside the matrix starting from (rw,cl).
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
void PLib::Matrix< T >::diag const T  a  ) 
 

sets the diagonal of the matrix to a

Sets the diagonal points of the matrix to a. The diagonal points are (0,0),(1,1),(2,2),etc.

Parameters:
a the value to set the diagonal to
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Matrix< T > PLib::Matrix< T >::flop  )  const
 

returns the matrix flopped

The flop pixel (i,j) = (i,cols-j-1)

Returns:
the flop of the matrix
Author:
Philippe Lavoie
Date:
2 May 1999

template<class T>
Matrix< T > PLib::Matrix< T >::get int  rw,
int  cl,
int  nr,
int  nc
const
 

returns the matrix of size (nr,nc) starting at (rw,cl).

Parameters:
rw the index of the row
cl the index of the column
nr the number of rows() of the matrix to generate
nc the number of coluns of the matrix to generate
Returns:
the matrix of size (nr,nc) starting at index (rw,cl).
Warning:
The matrix to return must fit inside the original matrix.
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Vector< T > PLib::Matrix< T >::getDiag  ) 
 

returns the diagonal of the matrix

Returns a vector with the component [i] being set to the component (i,i) of the matrix.

Returns:
the vector representing the diagonal of the matrix.
Author:
Philippe Lavoie
Date:
24 January 1997

Matrix< Complex > PLib::Matrix<>::herm  )  const
 

computes the hermitian of the matrix

This functions returns a matrix for which every elements (i,j) correspond to the element (j,i) of the original matrix.

Parameters:
a the a matrix
Returns:
A matrix corresponding to the hermitian of $a$
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
double PLib::Matrix< T >::norm void   ) 
 

Finds the first norm of the matrix.

Returns:
the norm of the matrix
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Matrix< unsigned char > & PLib::Matrix< T >::operator *= double  a  ) 
 

multiply every elements by a double

Parameters:
a the value to mutiply the elements with
Returns:
a reference to itself
Author:
Philippe Lavoie
Date:
1 June 1998

template<class T>
Matrix< unsigned char > & PLib::Matrix< T >::operator+= double  a  ) 
 

increase every elements by a double

Parameters:
a the value to increase the elements by
Returns:
a reference to itself
Author:
Philippe Lavoie
Date:
1 June 1998

template<class T>
Matrix< T > & PLib::Matrix< T >::operator+= const Matrix< T > &  a  ) 
 

adds a matrix to itself

Parameters:
a the matrix to increment itself with
Returns:
a reference to itself
Warning:
the matrix a must have a size compatible with the matrix
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Matrix< unsigned char > & PLib::Matrix< T >::operator-= double  a  ) 
 

decrease every elements by a double

Parameters:
a the value to decrease the elements by
Returns:
a reference to itself
Author:
Philippe Lavoie
Date:
1 June 1998

template<class T>
Matrix< T > & PLib::Matrix< T >::operator-= const Matrix< T > &  a  ) 
 

self substraction

This will substract the matrix a from the matrix. The result is thus matrix = matrix - a.

Parameters:
a the matrix to substract
Returns:
a reference to itself
Warning:
The matrix $a$ must be compatible with this matrix
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Matrix< unsigned char > & PLib::Matrix< T >::operator/= double  a  ) 
 

divide every elements by a double

Parameters:
a the value to divide the elements with
Returns:
a reference to itself
Author:
Philippe Lavoie
Date:
1 June 1998

template<class T>
Matrix< T > & PLib::Matrix< T >::operator= const Matrix< T > &  a  ) 
 

assignment operator

Parameters:
a the matrix to copy
Warning:
the matrix a must have compatible dimensions
Author:
Philippe Lavoie
Date:
24 January 1997

Reimplemented in PLib::MatrixRT< T >.

template<class T>
int PLib::Matrix< T >::read char *  filename,
int  r,
int  c
 

read a raw file containing a matrix of size $(r,c)$ Reads a file containing raw data of a matrix of size $(r,c)$.

Parameters:
filename the name of the file to read r the number of rows() c the number of columns
Returns:
1 if reading the file was successfull, 0 otherwise
Warning:
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
int PLib::Matrix< T >::read char *  filename  ) 
 

read a matrix file Reads a matrix file. The format of a file is { rows() cols() data...}, where rows() and cols() are int and data is a vector of the matrix type.

Parameters:
filename the name of the file to read
Returns:
1 if reading the file was successfull, 0 otherwise
Warning:
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
void PLib::Matrix< T >::submatrix int  sr,
int  sc,
Matrix< T > &  a
 

sets the submatrix (s_r,s_c) to a .

Parameters:
sr the row of the submatrix
sc the column of the submatrix
a the submatrix to copy from
Warning:
Since the size of a defines the size of the submatrices, this size must be such that a submatrix located at (s_r,s_c) exists.
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
T PLib::Matrix< T >::trace  )  const
 

The sum of all diagonal elements.

Parameters:
a the matrix to trace
Returns:
a value representing the sum of all diagonal elements
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Matrix< T > PLib::Matrix< T >::transpose  )  const
 

returns the transpose of the matrix

Parameters:
a the matrix to transpose
Returns:
the transpose of the matrix
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
int PLib::Matrix< T >::write char *  filename  ) 
 

write a matrix into a Matrix file Writes a matrix file. The format of the file is { rows() cols() data...}, where rows() and cols() are int and data is a vector of the matrix type.

Parameters:
filename the name of the file to write to
Returns:
Warning:
1 if reading the file was successfull, 0 otherwise
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
int PLib::Matrix< T >::writeRaw char *  filename  ) 
 

write the raw data to a file Writes the raw data to a file. The size information is {not} written to the file.

Parameters:
filename the name of the file to write to
Returns:
0 if an error occurs, 1 otherwise
Warning:
Author:
Philippe Lavoie
Date:
24 January 1997


Friends And Related Function Documentation

template<class T>
Vector<T> operator * const Matrix< T > &  a,
const Vector< T > &  x
[friend]
 

multiplies a matrix with a vector

Parameters:
a the matrix
x the vector
Returns:
returns a vector representing a x
Warning:
The matrix and the vector must be of compatible sizes
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Matrix<T> operator * const Complex &  d,
const Matrix< T > &  a
[friend]
 

multiplies a matrix with a complex value

Parameters:
d a complex value
a a matrix
Returns:
returns a matrix equal to d.A
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Matrix<T> operator * const Matrix< T > &  a,
const Matrix< T > &  b
[friend]
 

the multiplication operator

Parameters:
a a matrix
b the matrix to multiply with
Returns:
A matrix equal to $a b$
Warning:
The matrix must be compatible for the multiplication: a.cols() == b.rows()
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Matrix<T> operator+ const Matrix< T > &  a,
const Matrix< T > &  b
[friend]
 

the addition operator

Parameters:
a the first matrix to add
b the second matrix to add
Returns:
a matrix equal to $a+b$
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
Matrix<T> operator- const Matrix< T > &  a,
const Matrix< T > &  b
[friend]
 

the substraction operator

Parameters:
a the matrix to substract from
b the matrix to substract
Returns:
a matrix equal to a-b
Warning:
the matrix must be compatible
Author:
Philippe Lavoie
Date:
24 January 1997

template<class T>
int operator== const Matrix< T > &  a,
const Matrix< T > &  b
[friend]
 

the equality operator

Every elements are compared with each others. If one of them in matrix a is not equal to the one in matrix b, then the result is negative.

Parameters:
a the first matrix to compare
b the second matrix to compare
Returns:
1 if equal, 0 otherwise
Warning:
The matrices must be of compatible sizes
Author:
Philippe Lavoie
Date:
24 January 1997


The documentation for this class was generated from the following files:
Generated on Wed Dec 31 03:43:31 2003 for NURBS++ by doxygen 1.3.4