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

Find the roots of a real polynomial. More...

#include <vnl_rpoly_roots.h>

Public Member Functions

 vnl_rpoly_roots (const vnl_vector< double > &a)
 The constructor calculates the roots. More...
 
 vnl_rpoly_roots (const vnl_real_polynomial &poly)
 Calculate roots of a vnl_real_polynomial. Same comments apply. More...
 
std::complex< double > operator [] (int i) const
 Return i'th complex root. More...
 
vnl_vector< std::complex< double > > roots () const
 Complex vector of all roots. More...
 
const double & real (int i) const
 Real part of root I. More...
 
const double & imag (int i) const
 Imaginary part of root I. More...
 
vnl_vector< double > & real ()
 Vector of real parts of roots. More...
 
vnl_vector< double > & imag ()
 Vector of imaginary parts of roots. More...
 
vnl_vector< double > realroots (double tol=1e-12) const
 Return real roots only. More...
 
bool compute ()
 Compute roots using Jenkins-Traub algorithm. More...
 
bool compute_qr ()
 Compute roots using QR decomposition of companion matrix. [unimplemented]. More...
 
bool compute_laguerre ()
 Compute roots using Laguerre algorithm. [unimplemented]. More...
 

Protected Attributes

vnl_vector< double > coeffs_
 
vnl_vector< double > r_
 
vnl_vector< double > i_
 
int num_roots_found_
 

Detailed Description

Find the roots of a real polynomial.

Uses algorithm 493 from ACM Trans. Math. Software - the Jenkins-Traub algorithm, described by Numerical Recipes under "Other sure-fire techniques" as "practically a standard in black-box polynomial rootfinders". (See M.A. Jenkins, ACM TOMS 1 (1975) pp. 178-189.).

This class is not very const-correct as it is intended as a compute object rather than a data object.

Definition at line 37 of file vnl_rpoly_roots.h.

Constructor & Destructor Documentation

◆ vnl_rpoly_roots() [1/2]

vnl_rpoly_roots::vnl_rpoly_roots ( const vnl_vector< double > &  a)

The constructor calculates the roots.

This is the most efficient interface as all the result variables are initialized to the correct size. The polynomial is $ a[0] x^d + a[1] x^{d-1} + \cdots + a[d] = 0 $.

Note that if the routine fails, not all roots will be found. In this case, the "realroots" and "roots" functions will return fewer than n roots.

Definition at line 22 of file vnl_rpoly_roots.cxx.

◆ vnl_rpoly_roots() [2/2]

vnl_rpoly_roots::vnl_rpoly_roots ( const vnl_real_polynomial poly)

Calculate roots of a vnl_real_polynomial. Same comments apply.

Definition at line 33 of file vnl_rpoly_roots.cxx.

Member Function Documentation

◆ compute()

bool vnl_rpoly_roots::compute ( )

Compute roots using Jenkins-Traub algorithm.

Calls rpoly and interprets failure codes.

Definition at line 71 of file vnl_rpoly_roots.cxx.

◆ compute_laguerre()

bool vnl_rpoly_roots::compute_laguerre ( )

Compute roots using Laguerre algorithm. [unimplemented].

◆ compute_qr()

bool vnl_rpoly_roots::compute_qr ( )

Compute roots using QR decomposition of companion matrix. [unimplemented].

◆ imag() [1/2]

const double& vnl_rpoly_roots::imag ( int  i) const
inline

Imaginary part of root I.

Definition at line 67 of file vnl_rpoly_roots.h.

◆ imag() [2/2]

vnl_vector<double>& vnl_rpoly_roots::imag ( )
inline

Vector of imaginary parts of roots.

Definition at line 73 of file vnl_rpoly_roots.h.

◆ operator []()

std::complex<double> vnl_rpoly_roots::operator [] ( int  i) const
inline

Return i'th complex root.

Definition at line 58 of file vnl_rpoly_roots.h.

◆ real() [1/2]

const double& vnl_rpoly_roots::real ( int  i) const
inline

Real part of root I.

Definition at line 64 of file vnl_rpoly_roots.h.

◆ real() [2/2]

vnl_vector<double>& vnl_rpoly_roots::real ( )
inline

Vector of real parts of roots.

Definition at line 70 of file vnl_rpoly_roots.h.

◆ realroots()

vnl_vector< double > vnl_rpoly_roots::realroots ( double  tol = 1e-12) const

Return real roots only.

Roots are real if the absolute value of their imaginary part is less than the optional argument TOL. TOL defaults to 1e-12 [untested]

Definition at line 53 of file vnl_rpoly_roots.cxx.

◆ roots()

vnl_vector< std::complex< double > > vnl_rpoly_roots::roots ( ) const

Complex vector of all roots.

Definition at line 42 of file vnl_rpoly_roots.cxx.

Member Data Documentation

◆ coeffs_

vnl_vector<double> vnl_rpoly_roots::coeffs_
protected

Definition at line 93 of file vnl_rpoly_roots.h.

◆ i_

vnl_vector<double> vnl_rpoly_roots::i_
protected

Definition at line 96 of file vnl_rpoly_roots.h.

◆ num_roots_found_

int vnl_rpoly_roots::num_roots_found_
protected

Definition at line 98 of file vnl_rpoly_roots.h.

◆ r_

vnl_vector<double> vnl_rpoly_roots::r_
protected

Definition at line 95 of file vnl_rpoly_roots.h.


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