2 #ifndef vnl_polynomial_h_ 3 #define vnl_polynomial_h_ 35 # include <vcl_msvc_warnings.h> 38 #include "vnl/vnl_export.h" 62 vnl_polynomial(std::vector<T>
const& a): coeffs_(a) { assert(a.begin()==a.end() || a.back() != T(0)); }
69 vnl_polynomial(T
const* a,
unsigned len) { assert(len==0 || *a != T(0));
while (len--) coeffs_.push_back(a[len]); }
115 T evaluate(T
const& x)
const;
121 T
devaluate(T
const& x)
const {
return derivative().evaluate(x); }
143 int degree()
const {
return int(coeffs_.size()) - 1; }
146 T& operator [] (
unsigned int i) { assert(
int(i)<=degree());
return coeffs_[i]; }
148 T operator [] (
unsigned int i)
const { assert(
int(i)<=degree());
return coeffs_[i]; }
158 void print(std::ostream& os)
const;
170 #define VNL_POLYNOMIAL_INSTANTIATE(T) extern "please #include vnl/vnl_polynomial.hxx instead" 172 #endif // vnl_polynomial_h_ T evaluate_integral(T const &x1, T const &x2) const
Evaluate integral between x1 and x2.
T evaluate_integral(T const &x) const
Evaluate integral at x (assuming constant of integration is zero).
vnl_polynomial(int d=-1)
Initialize polynomial of a given degree.
vnl_polynomial(T const *a, unsigned len)
Initialize polynomial from C array, highest order first.
vnl_polynomial< T > & operator-=(vnl_polynomial< T > const &f)
vnl_vector< T > operator *(vnl_matrix_inverse< T > const &i, vnl_vector< T > const &B)
vnl_polynomial< T > & operator+=(vnl_polynomial< T > const &f)
std::vector< T > & coefficients()
Return the vector of coefficients.
void set_coefficients(std::vector< T > const &coeffs)
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
void print(std::ostream &os) const
Print this polynomial to stream.
T devaluate(T const &x) const
Evaluate derivative at value x.
const std::vector< T > & coefficients() const
Return the vector of coefficients.
vnl_polynomial< T > & operator%=(vnl_polynomial< T > const &f)
vnl_polynomial< T > & operator/=(vnl_polynomial< T > const &f)
std::vector< T > coeffs_
The coefficients of the polynomial.
vnl_bignum operator-(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the difference of two bignum numbers.
vnl_polynomial(std::vector< T > const &a)
Initialize the polynomial from its coefficients, lowest order first.
bool operator==(vnl_polynomial< T > const &p) const
comparison operator.
vnl_bignum operator+(vnl_bignum const &r1, long r2)
Returns the sum of two bignum numbers.
vnl_polynomial< T > operator-(vnl_polynomial< T > const &f) const
Returns polynomial which is difference of this with polynomial f.
vnl_bignum operator/(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the division of two bignum numbers.
vnl_polynomial(T const &a)
Initialize polynomial from single value, thus creating a monomial.
int degree() const
Return the degree (highest power of X) of the polynomial.
vnl_bignum operator%(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the remainder of r1 divided by r2.
Evaluation of polynomials.