Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

vnl_real_polynomial.h

Go to the documentation of this file.
00001 #ifndef vnl_real_polynomial_h_
00002 #define vnl_real_polynomial_h_
00003 
00004 
00005 // This is vxl/vnl/vnl_real_polynomial.h
00006 
00007 //:
00008 // \file
00009 // \brief Evaluation of real polynomials
00010 // \author Andrew W. Fitzgibbon, Oxford RRG, 06 Aug 96
00011 //
00012 // \warning 23 may 97, Peter Vanroose - "NO_COMPLEX" option added (until "complex" type is standardised)
00013 //
00014 
00015 // Modifications
00016 // 27/03/2001 Ian Scott and Tim Cootes - Added Binary IO
00017 // 27/03/2001 Ian Scott - Comments tidied up
00018 
00019 #include <vnl/vnl_vector.h>
00020 #include <vcl_complex.h>
00021 
00022 //:Evaluation of real polynomials at real and complex points.
00023 //    vnl_real_polynomial represents a univariate polynomial with real
00024 //    coefficients, stored as a vector of doubles.  This allows
00025 //    evaluation of the polynomial \f$p(x)\f$ at given values of \f$x\f$,
00026 //    or of its derivative \f$p'(x)\f$.
00027 //
00028 //    Roots may be extracted using the roots() method.
00029 class vnl_real_polynomial {
00030 public:
00031   //: Initialize polynomial.
00032   // The polynomial is \f$ a[0] x^d + a[1] x^{d-1} + \cdots + a[d] = 0 \f$.
00033   vnl_real_polynomial(vnl_vector<double> const & a): coeffs_(a) {}
00034 
00035   //: Initialize polynomial from C vector.
00036   // The parameter len is the number
00037   // of coefficients, one greater than the degree.
00038   vnl_real_polynomial(double const * a, int len): coeffs_(a, len) {}
00039 
00040   //: Initialize polynomial of a given degree.
00041   vnl_real_polynomial(int d): coeffs_(d+1) {}
00042 
00043 
00044   //: Evaluate polynomial at value x
00045   double evaluate(double x) const;
00046 
00047   //: Evaluate derivative at value x
00048 private: // not implemented
00049   double devaluate(double x) const;
00050 public:
00051 
00052   //: Evaluate polynomial at complex value x
00053   vcl_complex<double> evaluate(vcl_complex<double> const& x) const;
00054 
00055 
00056   //: Evaluate derivative at complex value x
00057   vcl_complex<double> devaluate(vcl_complex<double> const& x) const;
00058 
00059   // Data Access---------------------------------------------------------------
00060 
00061   //: Return the degree (highest power of x) of the polynomial.
00062   int     degree() const { return coeffs_.size() - 1; }
00063 
00064   //: Access to the polynomial coefficients
00065   double& operator [] (int i)       { return coeffs_[i]; }
00066   //: Access to the polynomial coefficients
00067   double  operator [] (int i) const { return coeffs_[i]; }
00068 
00069   //: Return the vector of coefficients
00070   const vnl_vector<double>& coefficients() const { return coeffs_; }
00071   //: Return the vector of coefficients
00072         vnl_vector<double>& coefficients()       { return coeffs_; }
00073 
00074   void set_coefficients(const vnl_vector<double> & coeffs) {coeffs_ = coeffs;}
00075 
00076 
00077 
00078 protected:
00079   //: The coefficients of the polynomial.
00080   // coeffs_[0] is the const term.
00081   // coeffs_[n] is the coefficient of the x^n term.
00082   vnl_vector<double> coeffs_;
00083 };
00084 
00085 
00086 
00087 
00088 
00089 #endif // vnl_real_polynomial_h_

Generated at Wed Mar 12 01:13:15 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000