Polynomials::Polynomial< number > Class Template Reference

Inheritance diagram for Polynomials::Polynomial< number >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 Polynomial (const std::vector< number > &coefficients)
 Polynomial ()
number value (const number x) const
void value (const number x, std::vector< number > &values) const
unsigned int degree () const
void scale (const number factor)
template<typename number2 >
void shift (const number2 offset)
Polynomial< number > derivative () const
Polynomial< number > primitive () const
Polynomial< number > & operator*= (const double s)
Polynomial< number > & operator*= (const Polynomial< number > &p)
Polynomial< number > & operator+= (const Polynomial< number > &p)
Polynomial< number > & operator-= (const Polynomial< number > &p)
void print (std::ostream &out) const

Static Protected Member Functions

static void scale (std::vector< number > &coefficients, const number factor)
template<typename number2 >
static void shift (std::vector< number > &coefficients, const number2 shift)
static void multiply (std::vector< number > &coefficients, const number factor)

Protected Attributes

std::vector< number > coefficients

Detailed Description

template<typename number>
class Polynomials::Polynomial< number >

Base class for all 1D polynomials. A polynomial is represented in this class by its coefficients, which are set through the constructor or by derived classes. Evaluation of a polynomial happens through the Horner scheme which provides both numerical stability and a minimal number of numerical operations.

Author:
Ralf Hartmann, Guido Kanschat, 2000, 2006

Constructor & Destructor Documentation

template<typename number>
Polynomials::Polynomial< number >::Polynomial ( const std::vector< number > &  coefficients  ) 

Constructor. The coefficients of the polynomial are passed as arguments, and denote the polynomial $\sum_i a[i] x^i$, i.e. the first element of the array denotes the constant term, the second the linear one, and so on. The degree of the polynomial represented by this object is thus the number of elements in the coefficient array minus one.

template<typename number>
Polynomials::Polynomial< number >::Polynomial (  )  [inline]

Default constructor creating an illegal object.


Member Function Documentation

template<typename number>
number Polynomials::Polynomial< number >::value ( const number  x  )  const

Return the value of this polynomial at the given point.

This function uses the Horner scheme for numerical stability of the evaluation.

template<typename number>
void Polynomials::Polynomial< number >::value ( const number  x,
std::vector< number > &  values 
) const

Return the values and the derivatives of the Polynomial at point x. values[i], i=0,...,values.size()-1 includes the ith derivative. The number of derivatives to be computed is thus determined by the size of the array passed.

This function uses the Horner scheme for numerical stability of the evaluation.

template<typename number >
unsigned int Polynomials::Polynomial< number >::degree (  )  const [inline]

Degree of the polynomial. This is the degree reflected by the number of coefficients provided by the constructor. Leading non-zero coefficients are not treated separately.

References Assert, and Polynomials::Polynomial< number >::coefficients.

template<typename number>
void Polynomials::Polynomial< number >::scale ( const number  factor  ) 

Scale the abscissa of the polynomial. Given the polynomial p(t) and the scaling t = ax, then the result of this operation is the polynomial q, such that q(x) = p(t).

The operation is performed in place.

template<typename number>
template<typename number2 >
void Polynomials::Polynomial< number >::shift ( const number2  offset  )  [inline]

Shift the abscissa oft the polynomial. Given the polynomial p(t) and the shift t = x + a, then the result of this operation is the polynomial q, such that q(x) = p(t).

The template parameter allows to compute the new coefficients with higher accuracy, since all computations are performed with type number2. This may be necessary, since this operation involves a big number of additions. On a Sun Sparc Ultra with Solaris 2.8, the difference between double and long double was not significant, though.

The operation is performed in place, i.e. the coefficients of the present object are changed.

template<typename number>
Polynomial<number> Polynomials::Polynomial< number >::derivative (  )  const

Compute the derivative of a polynomial.

template<typename number>
Polynomial<number> Polynomials::Polynomial< number >::primitive (  )  const

Compute the primitive of a polynomial. the coefficient of the zero order term of the polynomial is zero.

template<typename number>
Polynomial<number>& Polynomials::Polynomial< number >::operator*= ( const double  s  ) 

Multiply with a scalar.

template<typename number>
Polynomial<number>& Polynomials::Polynomial< number >::operator*= ( const Polynomial< number > &  p  ) 

Multiply with another polynomial.

template<typename number>
Polynomial<number>& Polynomials::Polynomial< number >::operator+= ( const Polynomial< number > &  p  ) 

Add a second polynomial.

template<typename number>
Polynomial<number>& Polynomials::Polynomial< number >::operator-= ( const Polynomial< number > &  p  ) 

Subtract a second polynomial.

template<typename number>
void Polynomials::Polynomial< number >::print ( std::ostream &  out  )  const

Print coefficients.

template<typename number>
static void Polynomials::Polynomial< number >::scale ( std::vector< number > &  coefficients,
const number  factor 
) [static, protected]

This function performs the actual scaling.

template<typename number>
template<typename number2 >
static void Polynomials::Polynomial< number >::shift ( std::vector< number > &  coefficients,
const number2  shift 
) [inline, static, protected]

This function performs the actual shift

template<typename number>
static void Polynomials::Polynomial< number >::multiply ( std::vector< number > &  coefficients,
const number  factor 
) [static, protected]

Multiply polynomial by a factor.


Member Data Documentation

template<typename number>
std::vector<number> Polynomials::Polynomial< number >::coefficients [protected]

Coefficients of the polynomial $\sum_i a_i x^i$. This vector is filled by the constructor of this class and may be passed down by derived classes.

This vector cannot be constant since we want to allow copying of polynomials.

Referenced by Polynomials::Polynomial< number >::degree().


The documentation for this class was generated from the following file:

deal.II documentation generated on Mon Nov 23 22:58:32 2009 by doxygen 1.6.1