MathTL
numerics/recursion.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_RECURSION_H
00011 #define _MATHTL_RECURSION_H
00012 
00013 #include <cmath>
00014 #include <algebra/polynomial.h>
00015 #include <algebra/vector.h>
00016 
00017 namespace MathTL
00018 {
00019   // some tools for three-term recursions
00020   // reference: Deuflhard/Bornemann, Numerische Mathematik 1
00021 
00026   class Recursion
00027   {
00028   public:
00029     virtual ~Recursion() {}
00030 
00031     virtual double a(const unsigned int k) const = 0;
00032     virtual double b(const unsigned int k) const = 0;
00033     virtual double c(const unsigned int k) const = 0;
00034 
00036     double operator () (const unsigned int n) const;
00037 
00039     double forwardSummation(const Vector<double>& coeffs) const;
00040 
00042 
00049     double adjointSummation(const Vector<double>& coeffs) const;
00050     
00051   protected:
00053     double p0_, p1_;
00054   };
00055 
00057   class HomogeneousRecursion : public Recursion
00058   {
00059   public:
00060     double c(const unsigned int k) const { return 0.0; }
00061   };
00062 
00064   class MonomialRecursion: public HomogeneousRecursion
00065   {
00066   public:
00067     MonomialRecursion(const double x) : x_(x) { p0_ = 1.0; p1_ = x_; }
00068 
00069     double a(const unsigned int k) const { return x_; }
00070     double b(const unsigned int k) const { return 0.0; }
00071 
00072   protected:
00073     double x_;
00074   };
00075 
00077   class ChebyshevRecursion : public HomogeneousRecursion
00078   {
00079   public:
00080     ChebyshevRecursion(const double x) : x_(x) { p0_ = 1.0; p1_ = x_; }
00081 
00082     double a(const unsigned int k) const { return 2*x_; }
00083     double b(const unsigned int k) const { return -1.0; }
00084 
00085   protected:
00086     double x_;
00087   };
00088 
00090   class CosineRecursion : public HomogeneousRecursion
00091   {
00092   public:
00093     CosineRecursion(const double x) : x_(x) { p0_ = 1.0; p1_ = cos(x_); }
00094 
00095     double a(const unsigned int k) const { return 2*cos(x_); }
00096     double b(const unsigned int k) const { return -1.0; }
00097 
00098   protected:
00099     double x_;
00100   };
00101 
00103   class SineRecursion : public HomogeneousRecursion
00104   {
00105   public:
00106     SineRecursion(const double x) : x_(x) { p0_ = 0.0; p1_ = sin(x_); }
00107 
00108     double a(const unsigned int k) const { return 2*cos(x_); }
00109     double b(const unsigned int k) const { return -1.0; }
00110 
00111   protected:
00112     double x_;
00113   };
00114   
00116   class JacobiRecursion : public HomogeneousRecursion
00117   {
00118   public:
00119     JacobiRecursion(const double a, const double b, const double x);
00120   
00121     double a(const unsigned int k) const;
00122     double b(const unsigned int k) const;
00123     
00124   protected:
00125     double a_, b_, x_;
00126   };
00127 
00129   class LegendreRecursion : public JacobiRecursion
00130   {
00131   public:
00132     LegendreRecursion(const double x) : JacobiRecursion(0.0,0.0,x) {}
00133   };
00134 }
00135 
00136 // include implementation of inline functions
00137 #include <numerics/recursion.cpp>
00138 
00139 #endif
 All Classes Functions Variables Typedefs Enumerations