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

vnl_real_npolynomial.h

Go to the documentation of this file.
00001 #ifndef vnl_real_npolynomial_h_
00002 #define vnl_real_npolynomial_h_
00003 
00004 // This is vxl/vnl/vnl_real_npolynomial.h
00005 
00006 //:
00007 //  \file
00008 //  \brief contains class for polynomials with N variables
00009 //  \authur Marc Pollefeys, ESAT-VISICS, K.U.Leuven, 12-08-97
00010 //  Implements a polynomial with N variables
00011 //
00012 
00013 //
00014 //  \verbatim
00015 //  Modifications
00016 //  Peter Vanroose 10 Oct 1999 - added simplify();
00017 //                               determine nterms_ nvar_ ideg_ automatically
00018 //  Peter Vanroose 20 Oct 1999 - Added operator+(), - * and ostream <<
00019 //  dac (Manchester) 15/03/2001: Tidied up the documentation + added binary_io
00020 //  \endverbatim
00021 
00022 
00023 //-----------------------------------------------------------------------------
00024 
00025 #include <vnl/vnl_vector.h>
00026 #include <vnl/vnl_matrix.h>
00027 
00028 //: real polynomial in N variables.
00029 //  \verbatim
00030 //    vnl_real_npolynomial represents a polynomial in multiple variables.
00031 //    Used by vnl_rnpoly_solve which solves systems of polynomial equations.
00032 //    Representation:  an N-omial (N terms) is represented by (1) a vector
00033 //    with the N coefficients (vnl_vector<double>), and (2) a matrix with
00034 //    N rows, the i-th row representing the exponents of term i, as follows:
00035 //    (vnl_matrix<int>) column k contains the (integer) exponent of variable
00036 //    k.  Example: the polynomial A*X^3 + B*X*Y + C*Y^2 + D*X*Y^2 is
00037 //    represented by the coefficients vector [A B C D] and the exponents
00038 //    matrix
00039 //    [3 0]
00040 //    [1 1]
00041 //    [0 2]
00042 //    [1 2].
00043 //  \endverbatim 
00044 //
00045 
00046 class vnl_real_npolynomial {
00047   friend class vnl_rnpoly_solve;
00048 
00049 public:
00050   
00051   // Constructor-----------------------------------------------------------------
00052   vnl_real_npolynomial() { } // don't use this. only here for the STL vector class.
00053   vnl_real_npolynomial(const vnl_vector<double>& c, const vnl_matrix<int>& p);
00054 
00055   // Computations--------------------------------------------------------------
00056 
00057   double eval(const vnl_vector<double>& x);
00058   int degree();
00059   vnl_real_npolynomial operator-() const; // unary minus
00060   vnl_real_npolynomial operator+(vnl_real_npolynomial const& ) const;
00061   vnl_real_npolynomial operator-(vnl_real_npolynomial const& ) const;
00062   vnl_real_npolynomial operator*(vnl_real_npolynomial const& ) const;
00063   vnl_real_npolynomial operator+(double ) const;
00064   vnl_real_npolynomial operator-(double P) const { return operator+(-P); }
00065   vnl_real_npolynomial operator*(double ) const;
00066   vnl_real_npolynomial& operator*=(double P) { coeffs_ *= P; return *this; }
00067   vnl_real_npolynomial operator/(double P) const { return operator*(1.0/P); }
00068   vnl_real_npolynomial& operator/=(double P) { return operator*=(1.0/P); }
00069   friend vcl_ostream& operator<<(vcl_ostream& , vnl_real_npolynomial const& );
00070 
00071 
00072   // nb also added functions to access the coeffs_ member variable
00073 
00074   // Data Access---------------------------------------------------------------
00075 
00076   //: Return the degree (highest power of x) of the polynomial.
00077   int degree() const { return coeffs_.size() - 1; }
00078 
00079   //: Access to the polynomial coefficients
00080   double& operator [] (int i)       { return coeffs_[i]; }
00081   //: Access to the polynomial coefficients
00082   double  operator [] (int i) const { return coeffs_[i]; }
00083 
00084   //: Return the vector of coefficients
00085   const vnl_vector<double>& coefficients() const { return coeffs_; }
00086   //: Return the vector of coefficients
00087   vnl_vector<double>& coefficients()       { return coeffs_; }
00088 
00089   //: Set vector of coefficients of each product
00090   void set(const vnl_vector<double> & c, const vnl_matrix<int> & p);
00091   
00092   //: Return the polynomial matrix 
00093   // (ie specifying the variables in each product)
00094   const vnl_matrix<int>& polyn() const { return polyn_; }
00095 
00096   //: Return the vector of coefficients
00097   vnl_matrix<int>& polyn()       { return polyn_; }
00098 
00099 
00100 private:
00101   void simplify();
00102   double eval(const vnl_matrix<double>& xn);
00103 
00104   // Data Members--------------------------------------------------------------
00105   //: coefficients
00106   vnl_vector<double> coeffs_; 
00107   //: degrees of every term for every variable
00108   vnl_matrix<int>    polyn_;  
00109   //: number of variables = # columns of polyn_
00110   int                nvar_;
00111   //: number of terms of polynomial
00112   int                nterms_; 
00113   //: max. degree of polynomial
00114   int                ideg_;   
00115 };
00116 
00117 
00118 #endif // vnl_real_npolynomial_h_

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