Controlpp
Loading...
Searching...
No Matches
controlpp::Polynom< T, Order > Class Template Reference

Describes a mathematical polynomial. More...

#include <controlpp/Polynom.hpp>

Public Types

using value_type = T
 
using vector_type = Eigen::Vector< T, eigen_vector_size >
 

Public Member Functions

 Polynom ()=default
 decault constructs the polynomials with the default values of their data type
 
 Polynom (const Polynom &)=default
 Copy constructor.
 
template<int OtherOrder>
requires (OtherOrder < Order)
 Polynom (const Polynom< T, OtherOrder > &other)
 
template<class... Args>
requires (Order != Eigen::Dynamic && (std::convertible_to<Args, T> && ...))
 Polynom (Args &&... args)
 
template<class... Args>
requires (Order == Eigen::Dynamic && (std::convertible_to<Args, T> && ...))
 Polynom (Args &&... args)
 
Polynomoperator= (const Polynom &)=default
 Copy assignment operator from polynomials with equal compile time size.
 
template<int M>
requires (M < Order)
Polynomoperator= (const Polynom< T, M > &other)
 Copy assignment from polynomials with smaller compile time size.
 
template<int M>
requires ((Order != Eigen::Dynamic) && (M == Order+1))
 Polynom (const T(&array)[M])
 Constructs a polynomial from an array.
 
template<int M>
requires ((Order != Eigen::Dynamic) && (M < Order+1))
 Polynom (const T(&array)[M])
 Constructs a polynomial from an array.
 
 Polynom (const T *values, size_t length)
 Constructs a dynamically sized polynomial from an array.
 
template<int M>
requires (Order == Eigen::Dynamic)
 Polynom (const T(&array)[M])
 Constructs a dynamically sized polynomial from an array.
 
template<int M>
requires ((Order != Eigen::Dynamic) && (M != Eigen::Dynamic) && (M == Order+1))
 Polynom (const Eigen::Vector< T, M > &vector)
 Constructs a polynomial from a vector.
 
template<class U >
requires (std::constructible_from<Eigen::Vector<T, eigen_vector_size>, U>)
 Polynom (const U &vector_expression)
 
template<int M>
requires ((Order != Eigen::Dynamic) && (M != Eigen::Dynamic) && (M < Order+1))
 Polynom (const Eigen::Vector< T, M > &vector)
 
template<std::same_as< T > U>
requires (Order == Eigen::Dynamic)
 Polynom (const Eigen::Vector< U, Eigen::Dynamic > &vector)
 
template<int M>
requires (Order == Eigen::Dynamic && M != Eigen::Dynamic)
 Polynom (const Eigen::Vector< T, M > &vector)
 
const T & at (size_t i) const
 Access elements at the i-th position.
 
T & at (size_t i)
 Access elements at the i-th position.
 
const T & operator[] (size_t i) const
 Access elements at the i-th position.
 
T & operator[] (size_t i)
 Access elements at the i-th position.
 
vector_typevector ()
 Returns the underlying vector that holds the values.
 
const vector_typevector () const
 Returns the underlying vector that holds the values.
 
size_t size () const
 returns the size of the polynomial
 
size_t order () const
 returns the order of the polynomial
 
void setZero ()
 sets all entries to zero
 
eval (const T &x) const
 Evaluates the polynomial at position x.
 
operator() (const T &x) const
 Evaluates the polynomial at position x
 
template<int M>
Eigen::Vector< T, M > eval (const Eigen::Vector< T, M > &x_vec) const
 Evaluates the polynomial at positions of the vector x_vec
 
template<int M>
Eigen::Vector< T, M > operator() (const Eigen::Vector< T, M > &x_vec) const
 Evaluates the polynomial at positions of the vector x_vec
 
std::complex< T > eval (const std::complex< T > &x) const
 Evaluates the polynomial at position x.
 
std::complex< T > operator() (const std::complex< T > &x) const
 Evaluates the polynomial at position x
 
template<int M>
Eigen::Vector< std::complex< T >, M > eval (const Eigen::Vector< std::complex< T >, M > &x_vec) const
 Evaluates the polynomial at positions of the vector x_vec
 
template<int M>
Eigen::Vector< std::complex< T >, M > operator() (const Eigen::Vector< std::complex< T >, M > &x_vec) const
 Evaluates the polynomial at positions of the vector x_vec
 
bool is_zero (T epsilon=std::numeric_limits< T >::min()) const
 Checks if every element in the polynomial is zero.
 
void print (std::ostream &stream, std::string_view var="x") const
 prints polynomial to an output character stream with a variale
 
void print (std::ostream &stream, std::function< std::string(int i)> var) const
 
template<int M>
requires (M <= Order)
Polynomoperator+= (const Polynom< T, M > &other)
 
template<int M>
requires (M <= Order)
Polynomoperator-= (const Polynom< T, M > &other)
 
template<std::convertible_to< T > U>
Polynomoperator*= (const U &num)
 
template<std::convertible_to< T > U>
Polynomoperator/= (const U &num)
 

Static Public Attributes

static constexpr int eigen_vector_size = (Order == Eigen::Dynamic) ? Eigen::Dynamic : Order + 1
 

Friends

std::ostream & operator<< (std::ostream &stream, const Polynom &poly)
 prints the polynomial (pretty) to an output stream with "x" as the symbol name of the variable
 

Detailed Description

template<class T, int Order>
class controlpp::Polynom< T, Order >

Describes a mathematical polynomial.

Describes polynomials in the form of:

\[ a_1 + a_2 x + a_3 x^2 .. \]

, where indices correspond to the parameter number and the potence

Template Parameters
TThe datatype of the polynomial parameters (e.g: float, double, complex)
OrderThe Order of the polynomial or Eigen::Dynamic for dynamically allocated sizes
AutoGrowIf true for at least one polynomial of an operation the resulting polynomial will grow automatically in size to contain all values. Usually set false if one needs to sum over polynomials in a loop.

Member Typedef Documentation

◆ value_type

template<class T , int Order>
using controlpp::Polynom< T, Order >::value_type = T

◆ vector_type

template<class T , int Order>
using controlpp::Polynom< T, Order >::vector_type = Eigen::Vector<T, eigen_vector_size>

Constructor & Destructor Documentation

◆ Polynom() [1/14]

template<class T , int Order>
controlpp::Polynom< T, Order >::Polynom ( )
default

decault constructs the polynomials with the default values of their data type

◆ Polynom() [2/14]

template<class T , int Order>
controlpp::Polynom< T, Order >::Polynom ( const Polynom< T, Order > &  )
default

Copy constructor.

◆ Polynom() [3/14]

template<class T , int Order>
template<int OtherOrder>
requires (OtherOrder < Order)
controlpp::Polynom< T, Order >::Polynom ( const Polynom< T, OtherOrder > &  other)
inline

◆ Polynom() [4/14]

template<class T , int Order>
template<class... Args>
requires (Order != Eigen::Dynamic && (std::convertible_to<Args, T> && ...))
controlpp::Polynom< T, Order >::Polynom ( Args &&...  args)
inlineexplicit

◆ Polynom() [5/14]

template<class T , int Order>
template<class... Args>
requires (Order == Eigen::Dynamic && (std::convertible_to<Args, T> && ...))
controlpp::Polynom< T, Order >::Polynom ( Args &&...  args)
inlineexplicit

◆ Polynom() [6/14]

template<class T , int Order>
template<int M>
requires ((Order != Eigen::Dynamic) && (M == Order+1))
controlpp::Polynom< T, Order >::Polynom ( const T(&)  array[M])
inlineexplicit

Constructs a polynomial from an array.

Parameters
arraythe values to be assigned to the polynomial

◆ Polynom() [7/14]

template<class T , int Order>
template<int M>
requires ((Order != Eigen::Dynamic) && (M < Order+1))
controlpp::Polynom< T, Order >::Polynom ( const T(&)  array[M])
inlineexplicit

Constructs a polynomial from an array.

Parameters
arraythe values to be assigned to the polynomial

◆ Polynom() [8/14]

template<class T , int Order>
controlpp::Polynom< T, Order >::Polynom ( const T *  values,
size_t  length 
)
inlineexplicit

Constructs a dynamically sized polynomial from an array.

Parameters
valuesA pointer to an array of values to be assigned to the polynom
lengthThe length of the values

◆ Polynom() [9/14]

template<class T , int Order>
template<int M>
requires (Order == Eigen::Dynamic)
controlpp::Polynom< T, Order >::Polynom ( const T(&)  array[M])
inlineexplicit

Constructs a dynamically sized polynomial from an array.

Template Parameters
MThe compile time size of the array
Parameters
arrayThe array

◆ Polynom() [10/14]

template<class T , int Order>
template<int M>
requires ((Order != Eigen::Dynamic) && (M != Eigen::Dynamic) && (M == Order+1))
controlpp::Polynom< T, Order >::Polynom ( const Eigen::Vector< T, M > &  vector)
inlineexplicit

Constructs a polynomial from a vector.

Parameters
vectorEigen::Vector object

◆ Polynom() [11/14]

template<class T , int Order>
template<class U >
requires (std::constructible_from<Eigen::Vector<T, eigen_vector_size>, U>)
controlpp::Polynom< T, Order >::Polynom ( const U &  vector_expression)
inlineexplicit

◆ Polynom() [12/14]

template<class T , int Order>
template<int M>
requires ((Order != Eigen::Dynamic) && (M != Eigen::Dynamic) && (M < Order+1))
controlpp::Polynom< T, Order >::Polynom ( const Eigen::Vector< T, M > &  vector)
inlineexplicit

◆ Polynom() [13/14]

template<class T , int Order>
template<std::same_as< T > U>
requires (Order == Eigen::Dynamic)
controlpp::Polynom< T, Order >::Polynom ( const Eigen::Vector< U, Eigen::Dynamic > &  vector)
inlineexplicit

◆ Polynom() [14/14]

template<class T , int Order>
template<int M>
requires (Order == Eigen::Dynamic && M != Eigen::Dynamic)
controlpp::Polynom< T, Order >::Polynom ( const Eigen::Vector< T, M > &  vector)
inlineexplicit

Member Function Documentation

◆ at() [1/2]

template<class T , int Order>
T & controlpp::Polynom< T, Order >::at ( size_t  i)
inline

Access elements at the i-th position.

Parameters
ithe value index to be accessed. Indices correspond to the order of the parameter
Returns
a mutable reference to the element

◆ at() [2/2]

template<class T , int Order>
const T & controlpp::Polynom< T, Order >::at ( size_t  i) const
inline

Access elements at the i-th position.

Parameters
ithe value index to be accessed. Indices correspond to the order of the parameter
Returns
an immutable reference to the element

◆ eval() [1/4]

template<class T , int Order>
template<int M>
Eigen::Vector< std::complex< T >, M > controlpp::Polynom< T, Order >::eval ( const Eigen::Vector< std::complex< T >, M > &  x_vec) const
inline

Evaluates the polynomial at positions of the vector x_vec

Parameters
x_vecA vector of input variable at which to evaluate the polynomial
Returns
The results of the polynomial evaluated at each of the vector elements

◆ eval() [2/4]

template<class T , int Order>
template<int M>
Eigen::Vector< T, M > controlpp::Polynom< T, Order >::eval ( const Eigen::Vector< T, M > &  x_vec) const
inline

Evaluates the polynomial at positions of the vector x_vec

Parameters
x_vecA vector of input variable at which to evaluate the polynomial
Returns
The results of the polynomial evaluated at each of the vector elements

◆ eval() [3/4]

template<class T , int Order>
std::complex< T > controlpp::Polynom< T, Order >::eval ( const std::complex< T > &  x) const
inline

Evaluates the polynomial at position x.

Returns
The result of the polynomial evaluated at the position x

◆ eval() [4/4]

template<class T , int Order>
T controlpp::Polynom< T, Order >::eval ( const T &  x) const
inline

Evaluates the polynomial at position x.

Returns
The result of the polynomial evaluated at the position x

◆ is_zero()

template<class T , int Order>
bool controlpp::Polynom< T, Order >::is_zero ( epsilon = std::numeric_limits<T>::min()) const
inline

Checks if every element in the polynomial is zero.

Parameters
epsilonA threshold below which everything is considered to be zero.
Returns
true if all elements are smaller than epsilon and false otherwise.

◆ operator()() [1/4]

template<class T , int Order>
template<int M>
Eigen::Vector< std::complex< T >, M > controlpp::Polynom< T, Order >::operator() ( const Eigen::Vector< std::complex< T >, M > &  x_vec) const
inline

Evaluates the polynomial at positions of the vector x_vec

Parameters
x_vecA vector of input variable at which to evaluate the polynomial
Returns
The results of the polynomial evaluated at each of the vector elements

◆ operator()() [2/4]

template<class T , int Order>
template<int M>
Eigen::Vector< T, M > controlpp::Polynom< T, Order >::operator() ( const Eigen::Vector< T, M > &  x_vec) const
inline

Evaluates the polynomial at positions of the vector x_vec

Parameters
x_vecA vector of input variable at which to evaluate the polynomial
Returns
The results of the polynomial evaluated at each of the vector elements

◆ operator()() [3/4]

template<class T , int Order>
std::complex< T > controlpp::Polynom< T, Order >::operator() ( const std::complex< T > &  x) const
inline

Evaluates the polynomial at position x

Parameters
xthe input variable of the polynomial
Returns
The result of the polynomial evaluated at the position x

◆ operator()() [4/4]

template<class T , int Order>
T controlpp::Polynom< T, Order >::operator() ( const T &  x) const
inline

Evaluates the polynomial at position x

Parameters
xthe input variable of the polynomial
Returns
The result of the polynomial evaluated at the position x

◆ operator*=()

template<class T , int Order>
template<std::convertible_to< T > U>
Polynom & controlpp::Polynom< T, Order >::operator*= ( const U &  num)
inline

◆ operator+=()

template<class T , int Order>
template<int M>
requires (M <= Order)
Polynom & controlpp::Polynom< T, Order >::operator+= ( const Polynom< T, M > &  other)
inline

◆ operator-=()

template<class T , int Order>
template<int M>
requires (M <= Order)
Polynom & controlpp::Polynom< T, Order >::operator-= ( const Polynom< T, M > &  other)
inline

◆ operator/=()

template<class T , int Order>
template<std::convertible_to< T > U>
Polynom & controlpp::Polynom< T, Order >::operator/= ( const U &  num)
inline

◆ operator=() [1/2]

template<class T , int Order>
Polynom & controlpp::Polynom< T, Order >::operator= ( const Polynom< T, Order > &  )
default

Copy assignment operator from polynomials with equal compile time size.

◆ operator=() [2/2]

template<class T , int Order>
template<int M>
requires (M < Order)
Polynom & controlpp::Polynom< T, Order >::operator= ( const Polynom< T, M > &  other)
inline

Copy assignment from polynomials with smaller compile time size.

◆ operator[]() [1/2]

template<class T , int Order>
T & controlpp::Polynom< T, Order >::operator[] ( size_t  i)
inline

Access elements at the i-th position.

Parameters
ithe value index to be accessed. Indices correspond to the order of the parameter
Returns
a mutable reference to the element

◆ operator[]() [2/2]

template<class T , int Order>
const T & controlpp::Polynom< T, Order >::operator[] ( size_t  i) const
inline

Access elements at the i-th position.

Parameters
ithe value index to be accessed. Indices correspond to the order of the parameter
Returns
an immutable reference to the element

◆ order()

template<class T , int Order>
size_t controlpp::Polynom< T, Order >::order ( ) const
inline

returns the order of the polynomial

the order can maxially be one smaller then the size of the polynomial. Takes zero data entries size_to account.

Returns
an size_teger value holding the order of the polynomial

◆ print() [1/2]

template<class T , int Order>
void controlpp::Polynom< T, Order >::print ( std::ostream &  stream,
std::function< std::string(int i)>  var 
) const
inline

◆ print() [2/2]

template<class T , int Order>
void controlpp::Polynom< T, Order >::print ( std::ostream &  stream,
std::string_view  var = "x" 
) const
inline

prints polynomial to an output character stream with a variale

Parameters
streamthe stream to be printed to
varthe symbol name of the variable

◆ setZero()

template<class T , int Order>
void controlpp::Polynom< T, Order >::setZero ( )
inline

sets all entries to zero

◆ size()

template<class T , int Order>
size_t controlpp::Polynom< T, Order >::size ( ) const
inline

returns the size of the polynomial

Note that the size is one larger than the order of the polynomial (assuming non-zero entries)

Returns
an size_teger value holding the size

◆ vector() [1/2]

template<class T , int Order>
vector_type & controlpp::Polynom< T, Order >::vector ( )
inline

Returns the underlying vector that holds the values.

Returns
A mutable reference to an Eigen::Vector object holding the values

◆ vector() [2/2]

template<class T , int Order>
const vector_type & controlpp::Polynom< T, Order >::vector ( ) const
inline

Returns the underlying vector that holds the values.

Returns
An immutable reference to an Eigen::Vector object holding the values

Friends And Related Symbol Documentation

◆ operator<<

template<class T , int Order>
std::ostream & operator<< ( std::ostream &  stream,
const Polynom< T, Order > &  poly 
)
friend

prints the polynomial (pretty) to an output stream with "x" as the symbol name of the variable

Parameters
streama reference to the output stream printed to
polythe polynomial to be printed
Returns
retuns the reference of the output stream

Member Data Documentation

◆ eigen_vector_size

template<class T , int Order>
constexpr int controlpp::Polynom< T, Order >::eigen_vector_size = (Order == Eigen::Dynamic) ? Eigen::Dynamic : Order + 1
staticconstexpr

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