Class Polynomial

Class Documentation

class Polynomial

Implementation of polynomials of order N-1.

Order must be known at compile time. Polynomial coefficients are stored with increasing powers, i.e. c_0 + c_1*t … c_{N-1} * t^{N-1} where N = number of coefficients of the polynomial.

Public Types

typedef std::vector<Polynomial> Vector

Public Functions

Polynomial(int N)
Polynomial(int N, const Eigen::VectorXd &coeffs)

Assigns arbitrary coefficients to a polynomial.

Polynomial(const Eigen::VectorXd &coeffs)
int N() const
bool operator==(const Polynomial &rhs) const
bool operator!=(const Polynomial &rhs) const
Polynomial operator+(const Polynomial &rhs) const
Polynomial &operator+=(const Polynomial &rhs)
Polynomial operator*(const Polynomial &rhs) const

The product of two polynomials is the convolution of their coefficients.

Polynomial operator*(const double &rhs) const

The product of a polynomial with a scalar.

Note that polynomials are in general not homogeneous, i.e., f(a*t) != a*f(t)

void setCoefficients(const Eigen::VectorXd &coeffs)

Sets up the internal representation from coefficients.

Coefficients are stored in increasing order with the power of t, i.e. c1 + c2*t + c3*t^2 ==> coeffs = [c1 c2 c3]

Eigen::VectorXd getCoefficients(int derivative = 0) const

Returns the coefficients for the specified derivative of the polynomial as a ROW vector.

void evaluate(double t, Eigen::VectorXd *result) const

Evaluates the polynomial at time t and writes the result.

Fills in all derivatives up to result.size()-1 (that is, if result is a 3-vector, then will fill in derivatives 0, 1, and 2).

double evaluate(double t, int derivative) const

Evaluates the specified derivative of the polynomial at time t and returns the result (only one value).

bool getRoots(int derivative, Eigen::VectorXcd *roots) const

Uses Jenkins-Traub to get all the roots of the polynomial at a certain derivative.

bool computeMinMaxCandidates(double t_start, double t_end, int derivative, std::vector<double> *candidates) const

Finds all candidates for the minimum and maximum between t_start and t_end by computing the roots of the derivative polynomial.

bool selectMinMaxFromRoots(double t_start, double t_end, int derivative, const Eigen::VectorXcd &roots_derivative_of_derivative, std::pair<double, double> *minimum, std::pair<double, double> *maximum) const

Evaluates the minimum and maximum of a polynomial between time t_start and t_end given the roots of the derivative.

Returns the minimum and maximum as pair<t, value>.

bool computeMinMax(double t_start, double t_end, int derivative, std::pair<double, double> *minimum, std::pair<double, double> *maximum) const

Computes the minimum and maximum of a polynomial between time t_start and t_end by computing the roots of the derivative polynomial.

Returns the minimum and maximum as pair<t, value>.

bool selectMinMaxFromCandidates(const std::vector<double> &candidates, int derivative, std::pair<double, double> *minimum, std::pair<double, double> *maximum) const

Selects the minimum and maximum of a polynomial among a candidate set.

Returns the minimum and maximum as pair<t, value>.

bool getPolynomialWithAppendedCoefficients(int new_N, Polynomial *new_polynomial) const

Increase the number of coefficients of this polynomial up to the specified degree by appending zeros.

void scalePolynomialInTime(double scaling_factor)

Scales the polynomial in time with a scaling factor.

To stretch out by a factor of 10, pass scaling_factor (b) = 1/10. To shrink by a factor of 10, pass scalign factor = 10. p_out = a12*b^12*t^12

  • a11*b^11*t^11… etc.

Public Static Functions

static bool selectMinMaxCandidatesFromRoots(double t_start, double t_end, const Eigen::VectorXcd &roots_derivative_of_derivative, std::vector<double> *candidates)

Finds all candidates for the minimum and maximum between t_start and t_end by evaluating the roots of the polynomial’s derivative.

static void baseCoeffsWithTime(int N, int derivative, double t, Eigen::VectorXd *coeffs)

Computes the base coefficients with the according powers of t, as e.g.

needed for computation of (in)equality constraints. Output: coeffs = vector to write the coefficients to Input: polynomial derivative for which the coefficients have to be computed Input: t = time of evaluation

static Eigen::VectorXd baseCoeffsWithTime(int N, int derivative, double t)

Convenience method to compute the base coefficents with time static void baseCoeffsWithTime(const Eigen::MatrixBase<Derived> & coeffs, int derivative, double t)

static Eigen::VectorXd convolve(const Eigen::VectorXd &data, const Eigen::VectorXd &kernel)

Discrete convolution of two vectors.

convolve(d, k)[m] = sum(d[m - n] * k[n])

static int getConvolutionLength(int data_size, int kernel_size)

Public Static Attributes

constexpr int kMaxN = 12

Maximum degree of a polynomial for which the static derivative (basis coefficient) matrix should be evaluated for.

kMaxN = max. number of coefficients.

constexpr int kMaxConvolutionSize = 2 * kMaxN - 2

kMaxConvolutionSize = max.

convolution size for N = 12, convolved with its derivative.

Eigen::MatrixXd base_coefficients_

One static shared across all members of the class, computed up to order kMaxConvolutionSize.