33 , ideg_(p.max_value())
43 for (
unsigned int row1=0; row1<
nterms_; ++row1)
44 for (
unsigned int row2=row1+1; row2<
nterms_; ++row2) {
47 if (col <
nvar_)
continue;
51 for (
unsigned int row=0; row<
nterms_; ++row)
55 for (
unsigned int i=0; i<
nvar_; ++i)
66 for (
unsigned int i=0; i<
nterms_; i++){
68 for (
unsigned int j=0; j<
nvar_; j++)
79 for (
unsigned int j=0; j<
nvar_; j++){
81 for (
unsigned int i=1; i<
ideg_+1; i++)
82 xn(j,i)=xn(j,i-1)*x(j);
96 for (
unsigned int j=0; j<
nvar_; j++) {
107 for (
unsigned int i = 0; i <
nterms_; i++) {
109 p(i,unk) = p(i,unk) - 1;
132 for (
unsigned int i=0; i<
nterms_; i++)
135 for (
unsigned int j=0; j<
nvar_; j++)
144 std::vector<unsigned int> d(
nvar_);
145 for (
unsigned int j=0; j<
nvar_; ++j)
148 for (
unsigned int i=0; i<
nterms_; ++i)
170 for (
unsigned int j=0; j<P.
nterms_; ++i,++j) coef(i) = P.
coeffs_(j);
174 for (
unsigned int k=0; k<
nvar_; ++k)
176 for (
unsigned int j=0; j<P.
nterms_; ++i,++j)
177 for (
unsigned int k=0; k<
nvar_; ++k)
178 poly(i,k) = P.
polyn_(j,k);
186 for (
unsigned int i=0; i<
nterms_; ++i)
191 for (
unsigned int i=0; i<
nterms_; ++i)
192 for (
unsigned int k=0; k<
nvar_; ++k)
194 for (
unsigned int k=0; k<
nvar_; ++k)
206 for (
unsigned int j=0; j<P.
nterms_; ++i,++j) coef(i) = - P.
coeffs_(j);
210 for (
unsigned int k=0; k<
nvar_; ++k)
212 for (
unsigned int j=0; j<P.
nterms_; ++i,++j)
213 for (
unsigned int k=0; k<
nvar_; ++k)
214 poly(i,k) = P.
polyn_(j,k);
225 for (
unsigned int i=0; i<
nterms_; ++i)
226 for (
unsigned int j=0; j<P.
nterms_; ++j,++k)
231 for (
unsigned int i=0; i<
nterms_; ++i)
232 for (
unsigned int j=0; j<P.
nterms_; ++j,++k)
233 for (
unsigned int l=0; l<
nvar_; ++l)
242 for (
unsigned int i=0; i<
nterms_; ++i)
252 return os << P.
asString() << std::endl;
255 *
this = (*this) + rhs;
259 *
this = (*this) - rhs;
263 *
this = (*this) * rhs;
268 std::ostringstream os;
270 for (
unsigned int i=0; i<
nterms_; ++i)
273 if (i>0 &&
coeffs_(i) >= 0) os <<
"+ ";
275 if (
coeffs_(i) < 0) { abs_coef = -abs_coef; os <<
"- "; }
276 if (abs_coef != 1) os << abs_coef <<
' ';
277 unsigned int totaldeg = 0;
284 if (totaldeg == 0 && abs_coef == 1) os << abs_coef;
287 for (
unsigned int i=0; i<
nterms_; ++i)
290 if (i>0 &&
coeffs_(i) >= 0) os <<
"+ ";
292 if (
coeffs_(i) < 0) { abs_coef = -abs_coef; os <<
"- "; }
293 if (abs_coef != 1) os << abs_coef <<
' ';
294 unsigned int totaldeg = 0;
295 for (
unsigned int j=0; j<
nvar_; ++j) {
296 if (
polyn_(i,j) > 0) os <<
'X' << j;
300 if (totaldeg == 0 && abs_coef == 1) os << abs_coef;
unsigned int cols() const
Return the number of columns.
double deval(const vnl_vector< double > &x, unsigned int i)
Evaluate the derivative of the polynomial at x with respect to the ith variable.
unsigned int nterms_
number of terms of polynomial.
unsigned int nvar_
number of variables = # columns of polyn_.
std::string asString() const
Return the textual representation of this polynomial.
vnl_matrix< T > extract(unsigned r, unsigned c, unsigned top=0, unsigned left=0) const
Extract a sub-matrix of size r x c, starting at (top,left).
void set(const vnl_vector< double > &c, const vnl_matrix< unsigned int > &p)
Set vector of coefficients of each product.
size_t size() const
Return the length, number of elements, dimension of this vector.
vnl_real_npolynomial operator *(vnl_real_npolynomial const &) const
vnl_real_npolynomial & operator-=(vnl_real_npolynomial const &rhs)
vnl_real_npolynomial deriv(unsigned int i)
Differentiate the polynomial with respect to the ith variable.
vnl_real_npolynomial & operator *=(vnl_real_npolynomial const &rhs)
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
vnl_vector< T > extract(size_t len, size_t start=0) const
Returns a subvector specified by the start index and length. O(n).
T max_value() const
Return maximum value of elements.
unsigned int degree() const
Return the degree (highest total power of all terms) of the polynomial.
unsigned int ideg_
max. degree of polynomial.
std::vector< unsigned int > degrees() const
Return the degrees (highest power of all terms) in each of the variables.
vnl_real_npolynomial & operator+=(vnl_real_npolynomial const &rhs)
void simplify()
Combine terms with identical exponents (i.e., identical rows in polyn_).
double eval(const vnl_vector< double > &x)
Evaluate the polynomial at x.
real polynomial in N variables.
vnl_real_npolynomial operator-() const
unsigned int rows() const
Return the number of rows.
vnl_matrix< unsigned int > polyn_
degrees of every term for every variable.
vnl_vector< double > coeffs_
coefficients.
contains class for polynomials with N variables
vnl_real_npolynomial operator+(vnl_real_npolynomial const &) const