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_SHIFTED_MATRIX_H 00011 #define _MATHTL_SHIFTED_MATRIX_H 00012 00013 #include <cassert> 00014 00015 namespace MathTL 00016 { 00018 template <class MATRIX> 00019 class ShiftedMatrix 00020 { 00021 public: 00025 typedef typename MATRIX::size_type size_type; 00026 00028 ShiftedMatrix(const MATRIX& A, const double lambda = 0) 00029 : A_(A), lambda_(lambda) 00030 { 00031 assert(A.row_dimension() == A.column_dimension()); 00032 } 00033 00035 void set_lambda(const double lambda) { lambda_ = lambda; } 00036 00038 const size_type row_dimension() const { return A_.column_dimension(); } 00039 00041 const size_type column_dimension() const { return A_.column_dimension(); } 00042 00044 template <class VECTOR> 00045 void apply(const VECTOR& x, VECTOR& result) const; 00046 00048 template <class VECTOR> 00049 void apply_transposed(const VECTOR& x, VECTOR& result) const; 00050 00051 private: 00052 const MATRIX& A_; 00053 double lambda_; 00054 }; 00055 00056 template <class MATRIX> template <class VECTOR> 00057 void ShiftedMatrix<MATRIX>::apply(const VECTOR& x, VECTOR& result) const 00058 { 00059 A_.apply(x, result); 00060 result.add(-lambda_, x); 00061 } 00062 00063 template <class MATRIX> template <class VECTOR> 00064 void ShiftedMatrix<MATRIX>::apply_transposed(const VECTOR& x, VECTOR& result) const 00065 { 00066 A_.apply_transposed(x, result); 00067 result.add(-lambda_, x); 00068 } 00069 } 00070 00071 #endif