Main Page   Class Hierarchy   Compound List   File List   Compound Members  

PLib::Matrix Class Template Reference

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

#include <matrix.h>

Inheritance diagram for PLib::Matrix:

PLib::Basic2DArray PLib::LUMatrix PLib::MatrixImage PLib::MatrixRT List of all members.

Public Methods

 Matrix (const int r, const int c)
 Matrix ()
 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

Definition at line 67 of file matrix.h.


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

Definition at line 157 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

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

Definition at line 284 of file matrix.cpp.

References PLib::Basic2DArray::cols, and PLib::Basic2DArray::rows.

Referenced by PLib::MatrixRT::MatrixRT, and PLib::MatrixRT::translate.

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

Definition at line 795 of file matrix.cpp.

References PLib::Basic2DArray::cols, and PLib::Basic2DArray::rows.

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

Definition at line 208 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

Referenced by PLib::NurbsCurve::leastSquares, and PLib::NurbsCurve::leastSquaresH.

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

Definition at line 309 of file matrix.cpp.

References PLib::Basic2DArray::cols, and PLib::Basic2DArray::rows.

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

Definition at line 771 of file matrix.cpp.

References PLib::Basic2DArray::cols, and PLib::Basic2DArray::rows.

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

Definition at line 250 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::init, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

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

Definition at line 368 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

template<class T>
Matrix< Color > & 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

Definition at line 328 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

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

Definition at line 409 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

template<class T>
Matrix< Color > & 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

Definition at line 348 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

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

Definition at line 469 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

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

Definition at line 388 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

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.

Definition at line 51 of file matrix.cpp.

References PLib::Basic2DArray::by_columns, PLib::Basic2DArray::cols, PLib::Basic2DArray::m, PLib::Basic2DArray::resize, and PLib::Basic2DArray::rows.

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

Definition at line 877 of file matrix.cpp.

References PLib::Basic2DArray::m, and PLib::Basic2DArray::resize.

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

read a matrix file Reads a matrix file. The format of a file is {\tt 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

Definition at line 844 of file matrix.cpp.

References PLib::Basic2DArray::m, and PLib::Basic2DArray::resize.

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

Definition at line 99 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

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

Definition at line 743 of file matrix.cpp.

References PLib::Basic2DArray::cols, and PLib::Basic2DArray::rows.

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

Definition at line 816 of file matrix.cpp.

References PLib::Basic2DArray::cols, and PLib::Basic2DArray::rows.

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 {\tt 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

Definition at line 902 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.

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

Definition at line 926 of file matrix.cpp.

References PLib::Basic2DArray::cols, PLib::Basic2DArray::m, and PLib::Basic2DArray::rows.


Friends And Related Function Documentation

template<class T>
Vector<T> operator * const Matrix< T > &   ,
const Vector< T > &   
[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

Definition at line 640 of file matrix.cpp.

template<class T>
Matrix<T> operator * const Complex &   ,
const Matrix< T > &   
[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

Definition at line 614 of file matrix.cpp.

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

multiplication of a double and a matrix.

Parameters:
d  the double value to scale the matrix with
a  the matrix to scale with the double value $d$
Returns:
A matrix equal to d.A
Author:
Philippe Lavoie
Date:
24 January 1997

Definition at line 588 of file matrix.cpp.

template<class T>
Matrix<T> operator * const Matrix< T > &   ,
const Matrix< T > &   
[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

Definition at line 532 of file matrix.cpp.

template<class T>
Matrix<T> operator+ const Matrix< T > &   ,
const Matrix< T > &   
[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

Definition at line 447 of file matrix.cpp.

template<class T>
Matrix<T> operator- const Matrix< T > &   ,
const Matrix< T > &   
[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

Definition at line 511 of file matrix.cpp.

template<class T>
int operator== const Matrix< T > &   ,
const Matrix< T > &   
[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

Definition at line 688 of file matrix.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jun 24 13:26:59 2003 for NURBS++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002