00001 #ifndef MATRIXSD_H
00002 #define MATRIXSD_H
00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032
00033
00034
00035 #include "matrix.h"
00043 #define MAT_CS(M,NR,I,J) (M[((J)*(2*(NR)-(J)+1)/2)+(I)-(J)])
00044 #define REF_CS(A,I,J) MAT_CS(((A).D)->m,((A).D)->nrow,I,J)
00045 #define THIS_CS(I,J) REF_CS(*this,I,J)
00046
00049 #ifdef USE_NAMESPACE_LINAL
00050 namespace LinAl {
00051 #endif
00052
00063 class MatrixSD:public MatrixC<double>
00064 {
00065 public:
00067
00068
00069 explicit MatrixSD () : MatrixC<double>() {}
00071 explicit MatrixSD (const int nr, const double value=0.0) :
00072 MatrixC<double>(nr*(nr+1)/2,1,value) {D->nrow=D->ncol=nr;}
00074 MatrixSD (const MatrixSD& B) : MatrixC<double>(B) {} ;
00076 ~MatrixSD () {} ;
00078 MatrixSD& operator = (const double value)
00079 {this->MatrixC<double>::operator=(value); return *this;}
00081
00082
00083
00084 void resize (const int nr, const double value=0.0) ;
00086 virtual int nr() const {return D->nrow;}
00087 virtual int nr(const int i) const {return D->nrow-i;}
00089 virtual int nc() const {return D->nrow;}
00090 virtual int nc(const int i) const {return i+1;}
00092 virtual Ref<double> operator () (const int i, const int j=0) {return MatrixC<double>::operator()(i,j);}
00094 virtual double operator () (const int i, const int j=0) const {assert(i>=j);return THIS_CS(i,j);}
00096
00097
00098 virtual void stream(ostream& s);
00100
00105
00106 MatrixSD transpose() const ;
00107 00108 00109 00110 00111 00112
00114 void multiply(const MatrixSD& A, const MatrixSD& B,
00115 const char TRANSA='N', const char TRANSB='N')
00116 {
00117 cout <<
00118 "Multiplication of two symmetric matrices destroys the symmetry. \n" <<
00119 "Therefore it doesnt quite make sense. Instead multiplication of \n" <<
00120 "a symmetric matrix with a full matrix is implemented as a member\n" <<
00121 "function of the full matrix class.\n" ;
00122 }
00124 void multiply(const double value);
00126 void multiply(const VectorD& x, VectorD& y, const double ALPHA=1.0, const double BETA=0.0) const;
00128 void CHdecompose() ;
00130 void CHsubstitute(MatrixC<double>& B) ;
00132 void CHsolve(MatrixC<double>& B) ;
00134 void CHinvert() ;
00136 protected:
00138 virtual double* ref(const int i, const int j) const {assert(i>=j);return &THIS_CS(i,j);}
00140 virtual double read(const int i, const int j) const {assert(i>=j);return THIS_CS(i,j);}
00142 virtual void write(const int i, const int j, const double v) {assert(i>=j);D=D->get_own_copy();THIS_CS(i,j)=v;}
00144 virtual void add(const int i, const int j, const double v) {assert(i>=j); D=D->get_own_copy();THIS_CS(i,j)+=v;}
00146 virtual void sub(const int i, const int j, const double v) {assert(i>=j); D=D->get_own_copy();THIS_CS(i,j)-=v;}
00148 virtual void mul(const int i, const int j, const double v) {assert(i>=j); D=D->get_own_copy();THIS_CS(i,j)*=v;}
00150 virtual void div(const int i, const int j, const double v) {assert(i>=j); D=D->get_own_copy();THIS_CS(i,j)/=v;}
00151 };
00152 #ifdef USE_NAMESPACE_LINAL
00153 }
00154 #endif
00155 #endif // #ifndef MATRIXSD_H