26 #include "polynomial.hpp"
27 #include "casadi_misc.hpp"
58 for (casadi_int d=0; d<
p_.size(); ++d) {
62 stream <<
" + " <<
p_[d] <<
"*x";
64 stream <<
" + " <<
p_[d] <<
"*x^" << d;
77 casadi_assert_dev(
degree()==0);
82 std::vector<double> p_ret(
p_.size() + a.
p_.size() - 1, 0);
83 for (casadi_int d=0; d<
p_.size(); ++d) {
84 for (casadi_int d_a=0; d_a<a.
p_.size(); ++d_a) {
85 p_ret[d+d_a] +=
p_[d] * a.
p_[d_a];
92 return *
this = *
this*d;
102 for (std::vector<double>::iterator it=
p_.begin(); it!=
p_.end(); ++it) {
114 p_.resize(std::max(
p_.size(), b.
p_.size()), 0);
115 transform(b.
p_.begin(), b.
p_.end(),
p_.begin(),
p_.begin(), std::plus<double>());
126 p_.resize(std::max(
p_.size(), b.
p_.size()), 0);
127 transform(
p_.begin(),
p_.begin()+b.
p_.size(),
128 b.
p_.begin(),
p_.begin(), std::minus<double>());
135 size_t new_size =
p_.size();
136 std::vector<double>::const_reverse_iterator it=
p_.rbegin();
137 while (it!=
p_.rend() && 0==*it++) new_size--;
142 std::vector<double> ret_p(
p_.size()-1);
143 for (casadi_int k=1; k<
p_.size(); ++k) {
144 ret_p[k-1] =
static_cast<double>(k)*
p_[k];
150 std::vector<double> ret_p(
p_.size()+1);
152 for (casadi_int k=0; k<
p_.size(); ++k) {
153 ret_p[k+1] =
p_[k]/
static_cast<double>(k+1);
Helper class for differentiating and integrating polynomials.
Polynomial operator+(const Polynomial &b) const
double scalar() const
Get scalar value (error if degree()!=0)
Polynomial(double scalar=1)
Construct a constant polynomial.
void trim()
Remove excess zeros.
Polynomial & operator/=(double b)
Polynomial & operator+=(const Polynomial &b)
Polynomial operator*(const Polynomial &b) const
Polynomial anti_derivative() const
Create a new polynomial for the anti-derivative (primitive function)
Polynomial operator-(const Polynomial &b) const
Polynomial derivative() const
Create a new polynomial for the derivative.
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.
Polynomial operator/(double b) const
Polynomial & operator-=(const Polynomial &b)
Polynomial & operator*=(const Polynomial &b)
casadi_int degree() const
Degree of the polynomial.