1 /* === S I N F G =========================================================== */
2 /*! \file polynomial_root.h
3 ** \brief Polynomial Root Finder Header
5 ** $Id: polynomial_root.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_POLYNOMIAL_ROOT_H
25 #define __SINFG_POLYNOMIAL_ROOT_H
27 /* === H E A D E R S ======================================================= */
32 /* === M A C R O S ========================================================= */
34 /* === T Y P E D E F S ===================================================== */
36 /* === C L A S S E S & S T R U C T S ======================================= */
37 template < typename T = float, typename F = float >
38 class Polynomial : public std::vector<T> //a0 + a1x + a2x^2 + ... + anx^n
42 //Will maintain all lower constants
43 void degree(unsigned int d, const T & def = (T)0) { resize(d+1,def); }
44 unsigned int degree()const { return size() - 1; }
46 const Polynomial & operator+=(const Polynomial &p)
49 resize(p.size(), (T)0);
51 for(int i = 0; i < p.size(); ++i)
58 const Polynomial & operator-=(const Polynomial &p)
61 resize(p.size(), (T)0);
63 for(int i = 0; i < p.size(); ++i)
70 const Polynomial & operator*=(const Polynomial &p)
79 std::vector<T> nc(*this);
81 //in place for constant stuff
82 for(i = 0; i < nc.size(); ++i)
87 if(p.size() < 2) return *this;
89 resize(size() + p.degree());
90 for(int i = 0; i < nc.size(); ++i)
92 for(int j = 1; j < p.size(); ++j)
94 nc[i+j] += nc[i]*p[j];
104 std::vector< std::complex<float> > workcoefs;
108 std::vector< std::complex<float> > coefs; //the number of coefficients determines the degree of polynomial
110 std::vector< std::complex<float> > roots;
112 void find_all_roots(bool polish);
117 /* === E N D =============================================================== */