Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Polynomials::Polynomial< number > Class Template Reference

#include <deal.II/base/polynomial.h>

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

Public Member Functions

 Polynomial (const std::vector< number > &coefficients)
 
 Polynomial (const unsigned int n)
 
 Polynomial (const std::vector< Point< 1 >> &lagrange_support_points, const unsigned int evaluation_point)
 
 Polynomial ()
 
number value (const number x) const
 
void value (const number x, std::vector< number > &values) const
 
void value (const number x, const unsigned int n_derivatives, 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)
 
bool operator== (const Polynomial< number > &p) const
 
void print (std::ostream &out) const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&) noexcept
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (Subscriptor &&) noexcept
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
template<typename StreamType >
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Protected Member Functions

void transform_into_standard_form ()
 

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
 
bool in_lagrange_product_form
 
std::vector< number > lagrange_support_points
 
number lagrange_weight
 

Additional Inherited Members

- Static Public Member Functions inherited from Subscriptor
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 

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.

There are two paths for evaluation of polynomials. One is based on the coefficients which are evaluated through the Horner scheme which is a robust general-purpose scheme. An alternative and more stable evaluation of high-degree polynomials with roots in the unit interval is provided by a product in terms of the roots. This form is available for special polynomials such as Lagrange polynomials or Legendre polynomials and used with the respective constructor. To obtain this more stable evaluation form, the constructor with the roots in form of a Lagrange polynomial must be used. In case a manipulation is done that changes the roots, the representation is switched to the coefficient form.

Author
Ralf Hartmann, Guido Kanschat, 2000, 2006, Martin Kronbichler, 2011, 2017

Definition at line 62 of file polynomial.h.

Constructor & Destructor Documentation

◆ Polynomial() [1/4]

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.

Definition at line 52 of file polynomial.cc.

◆ Polynomial() [2/4]

template<typename number>
Polynomials::Polynomial< number >::Polynomial ( const unsigned int  n)

Constructor creating a zero polynomial of degree n.

Definition at line 61 of file polynomial.cc.

◆ Polynomial() [3/4]

template<typename number>
Polynomials::Polynomial< number >::Polynomial ( const std::vector< Point< 1 >> &  lagrange_support_points,
const unsigned int  evaluation_point 
)

Constructor for a Lagrange polynomial and its point of evaluation. The idea is to construct \(\prod_{i\neq j} \frac{x-x_i}{x_j-x_i}\), where j is the evaluation point specified as argument and the support points contain all points (including x_j, which will internally not be stored).

Definition at line 70 of file polynomial.cc.

◆ Polynomial() [4/4]

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

Default constructor creating an illegal object.

Definition at line 766 of file polynomial.h.

Member Function Documentation

◆ value() [1/3]

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

Return the value of this polynomial at the given point.

This function uses the Horner scheme for numerical stability of the evaluation for polynomials in the coefficient form or the product of terms involving the roots if that representation is used.

Definition at line 792 of file polynomial.h.

◆ value() [2/3]

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 for polynomials in the coefficient form or the product of terms involving the roots if that representation is used.

Definition at line 99 of file polynomial.cc.

◆ value() [3/3]

template<typename number>
void Polynomials::Polynomial< number >::value ( const number  x,
const unsigned int  n_derivatives,
number *  values 
) const

Return the values and the derivatives of the Polynomial at point x. values[i], i=0,...,n_derivatives includes the ith derivative. The number of derivatives to be computed is determined by n_derivatives and values has to provide sufficient space for n_derivatives + 1 values.

This function uses the Horner scheme for numerical stability of the evaluation for polynomials in the coefficient form or the product of terms involving the roots if that representation is used.

Definition at line 110 of file polynomial.cc.

◆ degree()

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.

Definition at line 775 of file polynomial.h.

◆ scale() [1/2]

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.

Definition at line 297 of file polynomial.cc.

◆ shift() [1/2]

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

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.

Definition at line 571 of file polynomial.cc.

◆ derivative()

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

Compute the derivative of a polynomial.

Definition at line 590 of file polynomial.cc.

◆ primitive()

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.

Definition at line 619 of file polynomial.cc.

◆ operator*=() [1/2]

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

Multiply with a scalar.

Definition at line 335 of file polynomial.cc.

◆ operator*=() [2/2]

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

Multiply with another polynomial.

Definition at line 353 of file polynomial.cc.

◆ operator+=()

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

Add a second polynomial.

Definition at line 400 of file polynomial.cc.

◆ operator-=()

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

Subtract a second polynomial.

Definition at line 442 of file polynomial.cc.

◆ operator==()

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

Test for equality of two polynomials.

Definition at line 478 of file polynomial.cc.

◆ print()

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

Print coefficients.

Definition at line 646 of file polynomial.cc.

◆ serialize()

template<typename number >
template<class Archive >
void Polynomials::Polynomial< number >::serialize ( Archive &  ar,
const unsigned int  version 
)
inline

Write or read the data of this object to or from a stream for the purpose of serialization.

Definition at line 822 of file polynomial.h.

◆ scale() [2/2]

template<typename number>
void Polynomials::Polynomial< number >::scale ( std::vector< number > &  coefficients,
const number  factor 
)
staticprotected

This function performs the actual scaling.

Definition at line 280 of file polynomial.cc.

◆ shift() [2/2]

template<typename number>
template<typename number2 >
void Polynomials::Polynomial< number >::shift ( std::vector< number > &  coefficients,
const number2  shift 
)
staticprotected

This function performs the actual shift

Definition at line 509 of file polynomial.cc.

◆ multiply()

template<typename number>
void Polynomials::Polynomial< number >::multiply ( std::vector< number > &  coefficients,
const number  factor 
)
staticprotected

Multiply polynomial by a factor.

Definition at line 322 of file polynomial.cc.

◆ transform_into_standard_form()

template<typename number >
void Polynomials::Polynomial< number >::transform_into_standard_form ( )
protected

Transform polynomial form of product of linear factors into standard form, \(\sum_i a_i x^i\). Deletes all data structures related to the product form.

Definition at line 243 of file polynomial.cc.

Member Data Documentation

◆ coefficients

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.

Definition at line 264 of file polynomial.h.

◆ in_lagrange_product_form

template<typename number>
bool Polynomials::Polynomial< number >::in_lagrange_product_form
protected

Stores whether the polynomial is in Lagrange product form, i.e., constructed as a product \((x-x_0) (x-x_1) \ldots (x-x_n)/c\), or not.

Definition at line 270 of file polynomial.h.

◆ lagrange_support_points

template<typename number>
std::vector<number> Polynomials::Polynomial< number >::lagrange_support_points
protected

If the polynomial is in Lagrange product form, i.e., constructed as a product \((x-x_0) (x-x_1) \ldots (x-x_n)/c\), store the shifts \(x_i\).

Definition at line 276 of file polynomial.h.

◆ lagrange_weight

template<typename number>
number Polynomials::Polynomial< number >::lagrange_weight
protected

If the polynomial is in Lagrange product form, i.e., constructed as a product \((x-x_0) (x-x_1) \ldots (x-x_n)/c\), store the weight c.

Definition at line 282 of file polynomial.h.


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