31 #ifndef DOXYGEN_SHOULD_SKIP_THIS 33 # define SELECT(T) <T > 40 (
double const*,int,
double const&);
42 (
double const*,int,std::complex<double>
const&);
57 #endif // DOXYGEN_SHOULD_SKIP_THIS 80 for (
int i=d;i>=0;--i)
100 const unsigned int d1=f1.
degree();
101 const unsigned int d2=f2.
degree();
108 for (
unsigned int i=0; i<=d; ++i)
111 if (i<=d1) sum[d-i]+=f1[d1-i];
112 if (i<=d2) sum[d-i]+=f2[d2-i];
122 const unsigned int d1=f1.
degree();
123 const unsigned int d2=f2.
degree();
130 for (
unsigned int i=0; i<=d; ++i)
133 if (i<=d1) diff[d-i]+=f1[d1-i];
134 if (i<=d2) diff[d-i]-=f2[d2-i];
143 const unsigned int d1=f1.
degree();
144 const unsigned int d2=f2.
degree();
145 const unsigned int d = d1+d2;
150 for (
unsigned int i=0; i<=d1; ++i)
151 for (
unsigned int j=0; j<=d2; ++j)
152 prod[d-(i+j)] += f1[d1-i]*f2[d2-j];
158 *
this = (*this) + rhs;
164 *
this = (*this) - rhs;
170 *
this = (*this) * rhs;
177 double x1,
double x2)
179 double dx = std::fabs(x2-x1);
180 if (dx==0.0)
return 0;
185 return std::sqrt(area/dx);
193 for (
int i=d-1,di=1; i>=0; --i,++di)
205 for (
int i=d-1,di=1; i>=0; --i,++di)
213 bool first_coeff =
true;
215 for (
int i = 0; i <= d; ++i) {
216 if (
coeffs_[i] == 0.0)
continue;
218 if (
coeffs_[i] > 0.0 && !first_coeff) os <<
'+';
220 else if (
coeffs_[i] == -1.0) os <<
'-';
223 if (i < d-1) os <<
"X^" << d-i;
224 else if (i == d-1) os <<
'X';
227 if (first_coeff) os <<
" 0";
vnl_bignum operator+(vnl_bignum const &r1, long r2)
Returns the sum of two bignum numbers.
vnl_real_polynomial & operator *=(vnl_real_polynomial const &rhs)
Multiply rhs with this and return *this.
vnl_real_polynomial(vnl_vector< double > const &a)
Initialize polynomial.
vnl_real_polynomial & operator-=(vnl_real_polynomial const &rhs)
Subtract rhs from this and return *this.
T vnl_real_polynomial_evaluate(double const *a, int n, T const &x)
size_t size() const
Return the length, number of elements, dimension of this vector.
T const * data_block() const
Access the contiguous block storing the elements in the vector. O(1).
double evaluate(double x) const
Evaluate polynomial at value x.
const vnl_vector< double > & coefficients() const
Return the vector of coefficients.
Evaluation of real polynomials at real and complex points.
void print(std::ostream &os) const
Print this polynomial to stream.
VNL_EXPORT double vnl_rms_difference(const vnl_real_polynomial &f1, const vnl_real_polynomial &f2, double x1, double x2)
Returns RMS difference between f1 and f2 over range [x1,x2].
vnl_real_polynomial & operator+=(vnl_real_polynomial const &rhs)
Add rhs to this and return *this.
vnl_vector & fill(T const &v)
Set all values to v.
vnl_real_polynomial primitive() const
Return primitive function (inverse derivative) of this polynomial.
vnl_bignum operator-(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the difference of two bignum numbers.
vnl_real_polynomial derivative() const
Return derivative of this polynomial.
vnl_vector< double > coeffs_
The coefficients of the polynomial.
double devaluate(double x) const
Evaluate derivative at value x.
vnl_bignum operator *(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the product of two bignum numbers.
int degree() const
Return the degree (highest power of x) of the polynomial.
double evaluate_integral(double x) const
Evaluate integral at x (assuming constant of integration is zero).
Evaluation of real polynomials.