PFASST++
polynomial.hpp
Go to the documentation of this file.
1 
5 #ifndef _PFASST__POLYNOMIAL_HPP_
6 #define _PFASST__POLYNOMIAL_HPP_
7 
8 #include <vector>
9 using namespace std;
10 
11 
12 namespace pfasst
13 {
14  namespace quadrature
15  {
27  template<typename CoeffT>
28  class Polynomial
29  {
30  protected:
37  vector<CoeffT> c;
38 
39  public:
41  Polynomial(size_t n);
43 
45 
52  size_t order() const;
53 
65  CoeffT& operator[](const size_t i);
66 
74  Polynomial<CoeffT> differentiate() const;
75 
83  Polynomial<CoeffT> integrate() const;
85 
87 
94  template<typename xtype>
95  xtype evaluate(const xtype x) const
96  {
97  size_t n = this->order();
98  xtype v = c[n];
99  for (int j = n - 1; j >= 0; j--) {
100  v = x * v + c[j];
101  }
102  return v;
103  }
104 
110  Polynomial<CoeffT> normalize() const;
111 
117  vector<CoeffT> roots(size_t num_iterations=100, CoeffT ztol=1.0e-20) const;
119 
121 
127  static Polynomial<CoeffT> legendre(const size_t order);
129  };
130  } // ::pfasst::quadrature
131 } // ::pfasst
132 
134 
135 #endif // _PFASST__POLYNOMIAL_HPP_
Representation of a polynomial including differentiation, integration and root finding.
Definition: polynomial.hpp:28
STL namespace.
vector< CoeffT > c
Coefficients of the polynomial.
Definition: polynomial.hpp:37
xtype evaluate(const xtype x) const
Evaluate polynomial for given value.
Definition: polynomial.hpp:95