Public Member Functions | Protected Attributes | Related Functions | List of all members
vnl_real_polynomial Class Reference

Evaluation of real polynomials at real and complex points. More...

#include <vnl_real_polynomial.h>

Public Member Functions

 vnl_real_polynomial (vnl_vector< double > const &a)
 Initialize polynomial. More...
 
 vnl_real_polynomial (double const *a, unsigned len)
 Initialize polynomial from C vector. More...
 
 vnl_real_polynomial (double a)
 Initialize polynomial from double. More...
 
 vnl_real_polynomial (int d)
 Initialize polynomial of a given degree. More...
 
 vnl_real_polynomial (unsigned int d)
 
bool operator== (vnl_real_polynomial const &p) const
 comparison operator. More...
 
double evaluate (double x) const
 Evaluate polynomial at value x. More...
 
double evaluate_integral (double x) const
 Evaluate integral at x (assuming constant of integration is zero). More...
 
double evaluate_integral (double x1, double x2) const
 Evaluate integral between x1 and x2. More...
 
double devaluate (double x) const
 Evaluate derivative at value x. More...
 
std::complex< double > evaluate (std::complex< double > const &x) const
 Evaluate polynomial at complex value x. More...
 
std::complex< double > devaluate (std::complex< double > const &x) const
 Evaluate derivative at complex value x. More...
 
vnl_real_polynomial derivative () const
 Return derivative of this polynomial. More...
 
vnl_real_polynomial primitive () const
 Return primitive function (inverse derivative) of this polynomial. More...
 
vnl_real_polynomialoperator+= (vnl_real_polynomial const &rhs)
 Add rhs to this and return *this. More...
 
vnl_real_polynomialoperator-= (vnl_real_polynomial const &rhs)
 Subtract rhs from this and return *this. More...
 
vnl_real_polynomialoperator *= (vnl_real_polynomial const &rhs)
 Multiply rhs with this and return *this. More...
 
int degree () const
 Return the degree (highest power of x) of the polynomial. More...
 
double & operator [] (int i)
 Access to the polynomial coefficients. More...
 
double operator [] (int i) const
 Access to the polynomial coefficients. More...
 
const vnl_vector< double > & coefficients () const
 Return the vector of coefficients. More...
 
vnl_vector< double > & coefficients ()
 Return the vector of coefficients. More...
 
void set_coefficients (vnl_vector< double > const &coeffs)
 
void print (std::ostream &os) const
 Print this polynomial to stream. More...
 

Protected Attributes

vnl_vector< double > coeffs_
 The coefficients of the polynomial. More...
 

Related Functions

(Note that these are not member functions.)

void vsl_b_write (vsl_b_ostream &os, const vnl_real_polynomial &v)
 Binary save vnl_real_polynomial to stream. More...
 
void vsl_b_read (vsl_b_istream &is, vnl_real_polynomial &v)
 Binary load vnl_real_polynomial from stream. More...
 
void vsl_print_summary (std::ostream &os, const vnl_real_polynomial &b)
 Print human readable summary of object to a stream. More...
 
VNL_EXPORT vnl_real_polynomial operator+ (const vnl_real_polynomial &f1, const vnl_real_polynomial &f2)
 Returns polynomial which is sum of two polynomials f1(x)+f2(x). More...
 
VNL_EXPORT vnl_real_polynomial operator- (const vnl_real_polynomial &f1, const vnl_real_polynomial &f2)
 Returns polynomial which is different of two polynomials f1(x)-f2(x). More...
 
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]. More...
 

Detailed Description

Evaluation of real polynomials at real and complex points.

vnl_real_polynomial represents a univariate polynomial with real coefficients, stored as a vector of doubles. This allows evaluation of the polynomial $p(x)$ at given values of $x$, or of its derivative $p'(x)$.

The coefficients (coeffs_) are stored as a vnl_vector, where coeffs_[n] is the coefficient of the x^(d-n) term, where d is the degree of the polynomial. Otherwise said, the coefficients are stored starting with the highest degree term.

Roots may be extracted using the roots() method.

Definition at line 40 of file vnl_real_polynomial.h.

Constructor & Destructor Documentation

◆ vnl_real_polynomial() [1/5]

vnl_real_polynomial::vnl_real_polynomial ( vnl_vector< double > const &  a)
inline

Initialize polynomial.

The polynomial is $ a[0] x^d + a[1] x^{d-1} + \cdots + a[d] = 0 $.

Definition at line 45 of file vnl_real_polynomial.h.

◆ vnl_real_polynomial() [2/5]

vnl_real_polynomial::vnl_real_polynomial ( double const *  a,
unsigned  len 
)
inline

Initialize polynomial from C vector.

The parameter len is the number of coefficients, one greater than the degree.

Definition at line 52 of file vnl_real_polynomial.h.

◆ vnl_real_polynomial() [3/5]

vnl_real_polynomial::vnl_real_polynomial ( double  a)
inline

Initialize polynomial from double.

Useful when adding or multiplying a polynomial and a number.

Definition at line 58 of file vnl_real_polynomial.h.

◆ vnl_real_polynomial() [4/5]

vnl_real_polynomial::vnl_real_polynomial ( int  d)
inline

Initialize polynomial of a given degree.

Definition at line 61 of file vnl_real_polynomial.h.

◆ vnl_real_polynomial() [5/5]

vnl_real_polynomial::vnl_real_polynomial ( unsigned int  d)
inline

Definition at line 62 of file vnl_real_polynomial.h.

Member Function Documentation

◆ coefficients() [1/2]

const vnl_vector<double>& vnl_real_polynomial::coefficients ( ) const
inline

Return the vector of coefficients.

Definition at line 113 of file vnl_real_polynomial.h.

◆ coefficients() [2/2]

vnl_vector<double>& vnl_real_polynomial::coefficients ( )
inline

Return the vector of coefficients.

Definition at line 115 of file vnl_real_polynomial.h.

◆ degree()

int vnl_real_polynomial::degree ( ) const
inline

Return the degree (highest power of x) of the polynomial.

Definition at line 105 of file vnl_real_polynomial.h.

◆ derivative()

vnl_real_polynomial vnl_real_polynomial::derivative ( ) const

Return derivative of this polynomial.

Definition at line 189 of file vnl_real_polynomial.cxx.

◆ devaluate() [1/2]

double vnl_real_polynomial::devaluate ( double  x) const

Evaluate derivative at value x.

Definition at line 60 of file vnl_real_polynomial.cxx.

◆ devaluate() [2/2]

std::complex< double > vnl_real_polynomial::devaluate ( std::complex< double > const &  x) const

Evaluate derivative at complex value x.

Evaluate derivative at complex value x. Not implemented.

Definition at line 67 of file vnl_real_polynomial.cxx.

◆ evaluate() [1/2]

double vnl_real_polynomial::evaluate ( double  x) const

Evaluate polynomial at value x.

◆ evaluate() [2/2]

std::complex<double> vnl_real_polynomial::evaluate ( std::complex< double > const &  x) const

Evaluate polynomial at complex value x.

◆ evaluate_integral() [1/2]

double vnl_real_polynomial::evaluate_integral ( double  x) const

Evaluate integral at x (assuming constant of integration is zero).

Definition at line 73 of file vnl_real_polynomial.cxx.

◆ evaluate_integral() [2/2]

double vnl_real_polynomial::evaluate_integral ( double  x1,
double  x2 
) const

Evaluate integral between x1 and x2.

Definition at line 91 of file vnl_real_polynomial.cxx.

◆ operator *=()

vnl_real_polynomial & vnl_real_polynomial::operator *= ( vnl_real_polynomial const &  rhs)

Multiply rhs with this and return *this.

multiply rhs with this and return *this.

Definition at line 169 of file vnl_real_polynomial.cxx.

◆ operator []() [1/2]

double& vnl_real_polynomial::operator [] ( int  i)
inline

Access to the polynomial coefficients.

Definition at line 108 of file vnl_real_polynomial.h.

◆ operator []() [2/2]

double vnl_real_polynomial::operator [] ( int  i) const
inline

Access to the polynomial coefficients.

Definition at line 110 of file vnl_real_polynomial.h.

◆ operator+=()

vnl_real_polynomial & vnl_real_polynomial::operator+= ( vnl_real_polynomial const &  rhs)

Add rhs to this and return *this.

Definition at line 157 of file vnl_real_polynomial.cxx.

◆ operator-=()

vnl_real_polynomial & vnl_real_polynomial::operator-= ( vnl_real_polynomial const &  rhs)

Subtract rhs from this and return *this.

Definition at line 163 of file vnl_real_polynomial.cxx.

◆ operator==()

bool vnl_real_polynomial::operator== ( vnl_real_polynomial const &  p) const
inline

comparison operator.

Definition at line 65 of file vnl_real_polynomial.h.

◆ primitive()

vnl_real_polynomial vnl_real_polynomial::primitive ( ) const

Return primitive function (inverse derivative) of this polynomial.

Since a primitive function is not unique, the one with constant = 0 is returned

Definition at line 200 of file vnl_real_polynomial.cxx.

◆ print()

void vnl_real_polynomial::print ( std::ostream &  os) const

Print this polynomial to stream.

Definition at line 210 of file vnl_real_polynomial.cxx.

◆ set_coefficients()

void vnl_real_polynomial::set_coefficients ( vnl_vector< double > const &  coeffs)
inline

Definition at line 117 of file vnl_real_polynomial.h.

Friends And Related Function Documentation

◆ operator+()

VNL_EXPORT vnl_real_polynomial operator+ ( const vnl_real_polynomial f1,
const vnl_real_polynomial f2 
)
related

Returns polynomial which is sum of two polynomials f1(x)+f2(x).

Definition at line 97 of file vnl_real_polynomial.cxx.

◆ operator-()

VNL_EXPORT vnl_real_polynomial operator- ( const vnl_real_polynomial f1,
const vnl_real_polynomial f2 
)
related

Returns polynomial which is different of two polynomials f1(x)-f2(x).

Definition at line 119 of file vnl_real_polynomial.cxx.

◆ vnl_rms_difference()

VNL_EXPORT double vnl_rms_difference ( const vnl_real_polynomial f1,
const vnl_real_polynomial f2,
double  x1,
double  x2 
)
related

Returns RMS difference between f1 and f2 over range [x1,x2].

$\frac1{\sqrt{|x_2-x_1|}}\,\sqrt{\int_{x_1}^{x_2}\left(f_1(x)-f_2(x)\right)^2\,dx}$

Definition at line 176 of file vnl_real_polynomial.cxx.

◆ vsl_b_read()

void vsl_b_read ( vsl_b_istream &  is,
vnl_real_polynomial v 
)
related

Binary load vnl_real_polynomial from stream.

Definition at line 23 of file vnl_io_real_polynomial.cxx.

◆ vsl_b_write()

void vsl_b_write ( vsl_b_ostream &  os,
const vnl_real_polynomial v 
)
related

Binary save vnl_real_polynomial to stream.

Definition at line 13 of file vnl_io_real_polynomial.cxx.

◆ vsl_print_summary()

void vsl_print_summary ( std::ostream &  os,
const vnl_real_polynomial b 
)
related

Print human readable summary of object to a stream.

Definition at line 47 of file vnl_io_real_polynomial.cxx.

Member Data Documentation

◆ coeffs_

vnl_vector<double> vnl_real_polynomial::coeffs_
protected

The coefficients of the polynomial.

coeffs_.back() is the const term. coeffs_[n] is the coefficient of the x^(d-n) term, where d=coeffs_.size()-1

Invariant
coeffs_size() >= 1;

Definition at line 128 of file vnl_real_polynomial.h.


The documentation for this class was generated from the following files: