Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

matrixBD.h

Go to the documentation of this file.
00001 #ifndef MATRIXBD_H
00002 #define MATRIXBD_H
00003 /*------------------------------------------------------------------------------
00004  * matrixBD.h   A simple, easy to use and efficient Matrix library.
00005  *              Definition and partial implementation of class MatrixBD.
00006  *              
00007  *              Copyright 1997,1998,1999,2000 Roland Krause
00008  * -----------------------------------------------------------------------------
00009  * RCS/CVS history of changes
00010  *  
00011  * $Log: matrixBD.h,v $
00012  * Revision 1.3  2000/11/09 18:41:31  rokrau
00013  * The first commit to the sourceforge repostory. Update of all
00014  * intermediate changes makes this the official repository from now on.
00015  *
00016  * Revision 1.3  2000/11/09 17:51:53  rokrau
00017  * Removed one of the redundant multiplication methods.
00018  *
00019  * Revision 1.2  2000/10/27 17:08:09  rokrau
00020  * some fixes for integer matrices
00021  *
00022  * Revision 1.1  2000/10/24 06:03:04  rokrau
00023  * Split header files, made Ref constructor private w/ some drastic consequences for
00024  * Ref operators. A lot of minor changes.
00025  *
00026  * -----------------------------------------------------------------------------
00027  * $Date: 2000/11/09 18:41:31 $
00028  * $Revision: 1.3 $
00029  * $Author: rokrau $
00030  * $State: Exp $
00031  * -----------------------------------------------------------------------------
00032  */
00033 // standard includes
00034 // project includes
00035 #include    "matrix.h"
00043 #define MAT_CB(M,NR,I,J,KU) (M[(J)*((NR)-1)+(I)+(KU)])
00044 #define REF_CB(A,I,J) MAT_CB(((A).D)->m,((A).D)->nrow,I,J,((A).D)->ku)
00045 #define THIS_CB(I,J) REF_CB(*this,I,J)
00046 
00049 //using namespace std;
00050 #ifdef USE_NAMESPACE_LINAL
00051 namespace LinAl {
00052 #endif
00053 
00068 class MatrixBD:public MatrixC<double>
00069 {
00070 public:
00072 
00073 
00074     explicit MatrixBD() : MatrixC<double>() {}
00076     explicit MatrixBD(const int nr, const int nc, const int nu, const double value=0.0)
00077     : MatrixC<double>(nr,nc,nu,value) {}
00079     explicit MatrixBD(const int nr, const int nc=1, const double value=0.0)
00080     : MatrixC<double>(nr,nc,0,value) {}
00082     MatrixBD(const MatrixBD& B) : MatrixC<double>(B) {} ;
00084     ~MatrixBD() {} ;
00086     MatrixBD& operator= (const double value)
00087         {this->MatrixC<double>::operator=(value); return *this;}
00089 
00090 
00091 
00092     int nr() const ;
00094     int nr(const int j) const ;
00096     int nc() const ;
00098     int nc(const int i) const ;
00100     void resize(const int nr, const int nc, const double value=0) ;
00102     virtual Ref<double> operator() (const int i, const int j=0) {return MatrixC<double>::operator()(i,j);}
00104     virtual double operator() (const int i, const int j=0) const {return (THIS_CB(i,j));}
00106 
00107 
00108 
00109     int row_begin(const int j) const {int ja=j-D->ku;return (ja>0?ja:0);}
00111     int row_end(const int j) const {int je=j+D->kl+1;return (je<D->ncol?je:D->ncol);}
00113     int col_begin(const int i) const {int ia=i-D->kl;return (ia>0?ia:0);}
00115     int col_end(const int i) const {int ie=i+D->ku+1;return (ie<D->ncol?ie:D->ncol);}
00117     int ku() const {return D->ku;}
00119     int kl() const {return D->kl;}
00121 protected:
00123     double* ref(const int i, const int j) const {assert(i>=j-D->ku);assert((i-j)<D->nrow);return &THIS_CB(i,j);}
00125     double read(const int i, const int j) const {assert(i>=j-D->ku);return (((i-j)<D->nrow)?THIS_CB(i,j):0.0);}
00126     // need to throw an exception to warn user that he cant write
00127     // outside the band of the matrix
00129     void write(const int i, const int j, const double v) {assert(i>=j-D->ku);if ((i-j)<D->nrow) {D=D->get_own_copy();THIS_CB(i,j)=v;}}
00131     void add(const int i, const int j, const double v) {assert(i>=j-D->ku);if ((i-j)<D->nrow) {D=D->get_own_copy();THIS_CB(i,j)+=v;}}
00133     void sub(const int i, const int j, const double v) {assert(i>=j-D->ku);if ((i-j)<D->nrow) {D=D->get_own_copy();THIS_CB(i,j)-=v;}}
00135     void mul(const int i, const int j, const double v) {assert(i>=j-D->ku);if ((i-j)<D->nrow) {D=D->get_own_copy();THIS_CB(i,j)*=v;}}
00137     void div(const int i, const int j, const double v) {assert(i>=j-D->ku);if ((i-j)<D->nrow) {D=D->get_own_copy();THIS_CB(i,j)/=v;}}
00138 public:
00140     virtual void stream(ostream& s);
00145 
00146     MatrixBD transpose() const ;
00147     /*
00148      * Multiplication of two symmetric matrices destroys the symmetry.
00149      * Therefore it doesnt quite make sense. Instead multiplication of a
00150      * symmetric matrix with a full matrix can be implemented as a member
00151      * function of the full matrix class.
00152      */
00154     void multiply(const MatrixBD& A, const MatrixBD& B,
00155                   const char TRANSA='N', const char TRANSB='N')
00156     {
00157     cout <<
00158         "Multiplication of two symmetric matrices destroys the symmetry. \n" <<
00159         "Therefore it doesnt quite make sense. Instead multiplication of \n" <<
00160         "a symmetric matrix with a full matrix is implemented as a member\n" <<
00161         "function of the full matrix class.\n" ;
00162     }
00164     void multiply(const VectorD& x, VectorD& y, const char TRANS='N',
00165                   const double ALPHA=1.0, const double BETA=0.0) const;
00167     void multiply(const double value);
00169     void LUdecompose(int* IPIV) ;
00175     void LUsubstitute(MatrixC<double>& B, int* IPIV) ;
00177     void LUsolve(MatrixC<double>& B) ;
00179     void LUinvert()
00180     {
00181     cout <<
00182         "Inversion of a banded matrix does in general not preserve the\n" <<
00183         "banded structure of the matrix. It is therefore not supported\n" <<
00184         "in this form.\n" ;
00185     }
00187     void CHdecompose() ;
00189     void CHsubstitute(MatrixC<double>& B) ;
00191     void CHsolve(MatrixC<double>& B) ;
00193     void CHinvert()
00194     {
00195     cout <<
00196         "Inversion of a banded matrix does in general not preserve the\n" <<
00197         "banded structure of the matrix. It is therefore not supported\n" <<
00198         "in this form.\n" ;
00199     }
00200 };
00201 #ifdef USE_NAMESPACE_LINAL
00202 } // namespace LinAl
00203 #endif
00204 #endif // #ifndef MATRIXBD_H

Generated at Wed Nov 22 08:38:28 2000 for LinAl - a simple and efficient Matrix library - by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000