MathTL
numerics/decomposable_matrix.h
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_DECOMPOSABLE_MATRIX_H
00011 #define _MATHTL_DECOMPOSABLE_MATRIX_H
00012 
00013 #include <iostream>
00014 #include <algebra/vector.h>
00015 #include <algebra/matrix.h>
00016 #include <utils/array1d.h>
00017 
00018 // matrix norms, for convenience
00019 #include <algebra/matrix_norms.h>
00020 
00021 namespace MathTL
00022 {
00034   template <class C>
00035   class DecomposableMatrix
00036     : protected Matrix<C>
00037   {
00038   public:
00042     typedef typename Vector<C>::size_type size_type;
00043 
00047     enum DecompositionType {
00048       none,
00049       LU,
00050       QU
00051     };
00052 
00056     explicit DecomposableMatrix(const size_type n = 0);
00057 
00061     DecomposableMatrix(const DecomposableMatrix<C>& M);
00062 
00066     DecomposableMatrix(const Matrix<C>& M);
00067 
00071     DecomposableMatrix<C>& operator = (const DecomposableMatrix<C>& M);
00072 
00076     const size_type row_dimension() const;
00077 
00081     const size_type column_dimension() const;
00082 
00086     const size_type size() const;
00087 
00091     void decompose(DecompositionType d = LU);
00092 
00097     void solve(const Vector<C>& b, Vector<C>& x,
00098                DecompositionType d = LU);
00099 
00104     void print(std::ostream& os,
00105                const unsigned int tabwidth = 10,
00106                const unsigned int precision = 3) const;
00107 
00108  protected:
00109     // decomposition type
00110     DecompositionType decomposition;
00111 
00112     // storage for row equilibration matrix entries (-> LU factorization)
00113     Vector<double> D;
00114 
00115     // storage for permuation matrix (-> LU factorization)
00116     Array1D<size_type> P;
00117 
00118     // LU decomposition (row equilibration, row pivoting, in place (up to D and P))
00119     void LU_decomposition();
00120 
00121     // QR decomposition (in place)
00122     void QU_decomposition();
00123 
00124     // revert decomposition
00125     void revert_decomposition();
00126   };
00127 
00131   template <class C>
00132   std::ostream& operator << (std::ostream& os, const DecomposableMatrix<C>& M);
00133 }
00134 
00135 // include implementation of inline functions
00136 #include <numerics/decomposable_matrix.cpp>
00137 
00138 #endif
 All Classes Functions Variables Typedefs Enumerations