MathTL
|
00001 // -*- c++ -*- 00002 00003 // +--------------------------------------------------------------------+ 00004 // | This file is part of MathTL - the Mathematical Template Library | 00005 // | | 00006 // | Copyright (c) 2002-2009 | 00007 // | Thorsten Raasch, Manuel Werner | 00008 // +--------------------------------------------------------------------+ 00009 00010 #ifndef _MATHTL_TRIANGULAR_MATRIX_H 00011 #define _MATHTL_TRIANGULAR_MATRIX_H 00012 00013 #include <iostream> 00014 #include <algebra/vector.h> 00015 00016 // matrix norms, for convenience 00017 #include <algebra/matrix_norms.h> 00018 00019 namespace MathTL 00020 { 00029 template <class C> 00030 class LowerTriangularMatrix 00031 { 00032 public: 00036 typedef typename Vector<C>::size_type size_type; 00037 00041 explicit LowerTriangularMatrix(const size_type n = 0); 00042 00046 LowerTriangularMatrix(const LowerTriangularMatrix<C>& M); 00047 00051 LowerTriangularMatrix(const size_type rows, const size_type columns); 00052 00061 LowerTriangularMatrix(const size_type rows, 00062 const size_type columns, 00063 const char* str, 00064 const bool byrow = true); 00065 00069 const size_type row_dimension() const; 00070 00074 const size_type column_dimension() const; 00075 00079 const size_type size() const; 00080 00084 void resize(const size_type rows, const size_type columns); 00085 00089 const size_type memory_consumption() const; 00090 00094 bool empty() const; 00095 00099 const C operator () (const size_type row, const size_type column) const; 00100 00104 const C get_entry(const size_type row, const size_type column) const; 00105 00109 C& operator () (const size_type row, const size_type column); 00110 00114 void set_entry(const size_type row, const size_type column, const C value); 00115 00119 template <class C2> 00120 bool operator == (const LowerTriangularMatrix<C2>& M) const; 00121 00125 template <class C2> 00126 bool operator != (const LowerTriangularMatrix<C2>& M) const; 00127 00131 LowerTriangularMatrix<C>& operator = (const LowerTriangularMatrix<C>& M); 00132 00136 void scale(const C s); 00137 00141 void inverse(LowerTriangularMatrix<C>& MInv) const; 00142 00148 template <class VECTOR> 00149 void apply(const VECTOR& x, VECTOR& Mx) const; 00150 00156 template <class VECTOR> 00157 void apply_transposed(const VECTOR& x, VECTOR& Mtx) const; 00158 00163 void print(std::ostream& os, 00164 const unsigned int tabwidth = 10, 00165 const unsigned int precision = 3) const; 00166 00167 protected: 00171 static size_type triangle_size(const size_type rows, const size_type columns); 00172 00177 static size_type triangle_index(const size_type row, 00178 const size_type column, 00179 const size_type rowdim, 00180 const size_type coldim); 00181 00187 Vector<C> entries_; 00188 00192 size_type rowdim_; 00193 00197 size_type coldim_; 00198 }; 00199 00205 template <class C> 00206 LowerTriangularMatrix<C> operator * (const LowerTriangularMatrix<C>& M, 00207 const LowerTriangularMatrix<C>& N); 00208 00212 template <class C> 00213 std::ostream& operator << (std::ostream& os, const LowerTriangularMatrix<C>& M); 00214 00215 00224 template <class C> 00225 class UpperTriangularMatrix 00226 : public LowerTriangularMatrix<C> 00227 { 00228 public: 00232 typedef typename LowerTriangularMatrix<C>::size_type size_type; 00233 00237 explicit UpperTriangularMatrix(const size_type n = 0); 00238 00242 UpperTriangularMatrix(const UpperTriangularMatrix<C>& M); 00243 00247 UpperTriangularMatrix(const size_type rows, const size_type columns); 00248 00257 UpperTriangularMatrix(const size_type rows, 00258 const size_type columns, 00259 const char* str, 00260 const bool byrow = true); 00261 00265 const size_type row_dimension() const; 00266 00270 const size_type column_dimension() const; 00271 00275 void resize(const size_type rows, const size_type columns); 00276 00280 const C operator () (const size_type row, const size_type column) const; 00281 00285 const C get_entry(const size_type row, const size_type column) const; 00286 00290 C& operator () (const size_type row, const size_type column); 00291 00295 void set_entry(const size_type row, const size_type column, const C value); 00296 00300 template <class C2> 00301 bool operator == (const UpperTriangularMatrix<C2>& M) const; 00302 00306 template <class C2> 00307 bool operator != (const UpperTriangularMatrix<C2>& M) const; 00308 00312 UpperTriangularMatrix<C>& operator = (const UpperTriangularMatrix<C>& M); 00313 00317 void inverse(UpperTriangularMatrix<C>& MInv) const; 00318 00324 template <class VECTOR> 00325 void apply(const VECTOR& x, VECTOR& Mx) const; 00326 00332 template <class VECTOR> 00333 void apply_transposed(const VECTOR& x, VECTOR& Mtx) const; 00334 00339 void print(std::ostream& os, 00340 const unsigned int tabwidth = 10, 00341 const unsigned int precision = 3) const; 00342 }; 00343 00347 template <class C> 00348 std::ostream& operator << (std::ostream& os, const UpperTriangularMatrix<C>& M); 00349 } 00350 00351 // include implementation of inline functions 00352 #include <algebra/triangular_matrix.cpp> 00353 00354 #endif