ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/math/Polynomial.hpp
(Generate patch)

Comparing trunk/OOPSE-4/src/math/Polynomial.hpp (file contents):
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
Revision 2576 by tim, Mon Jan 30 22:25:27 2006 UTC

# Line 74 | Line 74 | namespace oopse {
74    class Polynomial {
75  
76    public:
77 <        
77 >    typedef Polynomial<ElemType> PolynomialType;    
78      typedef int ExponentType;
79      typedef ElemType CoefficientType;
80      typedef std::map<ExponentType, CoefficientType> PolynomialPairMap;
81      typedef typename PolynomialPairMap::iterator iterator;
82      typedef typename PolynomialPairMap::const_iterator const_iterator;
83 +
84 +    Polynomial() {}
85 +    Polynomial(ElemType v) {setCoefficient(0, v);}
86      /**
87       * Calculates the value of this Polynomial evaluated at the given x value.
88       * @return The value of this Polynomial evaluates at the given x value
# Line 185 | Line 188 | namespace oopse {
188      size_t size() {
189        return polyPairMap_.size();
190      }
191 <        
191 >
192 >    PolynomialType& operator += (const PolynomialType& p) {
193 >        typename Polynomial<ElemType>::const_iterator i;
194 >
195 >        for (i =  p.begin(); i  != p.end(); ++i) {
196 >          this->addCoefficient(i->first, i->second);
197 >        }
198 >
199 >        return *this;        
200 >    }
201 >
202 >    PolynomialType& operator -= (const PolynomialType& p) {
203 >        typename Polynomial<ElemType>::const_iterator i;
204 >        for (i =  p.begin(); i  != p.end(); ++i) {
205 >          this->addCoefficient(i->first, -i->second);
206 >        }        
207 >    }
208 >
209 >    PolynomialType& operator *= (const PolynomialType& p) {
210 >    typename Polynomial<ElemType>::const_iterator i;
211 >    typename Polynomial<ElemType>::const_iterator j;
212 >    
213 >    for (i = this->begin(); i !=this->end(); ++i) {
214 >      for (j = p.begin(); j !=p.end(); ++j) {
215 >        this->addCoefficient( i->first + j->first, i->second * j->second);
216 >      }
217 >    }
218 >
219 >    return *this;
220 >    }
221 >
222 >  
223    private:
224          
225      PolynomialPairMap polyPairMap_;
# Line 211 | Line 245 | namespace oopse {
245      return p;
246    }
247  
248 +  template<typename ElemType>
249 +  Polynomial<ElemType> operator *(const Polynomial<ElemType>& p, const ElemType v) {
250 +    typename Polynomial<ElemType>::const_iterator i;
251 +    Polynomial<ElemType> result;
252 +    
253 +    for (i = p.begin(); i !=p.end(); ++i) {
254 +        result.addCoefficient( i->first , i->second * v);
255 +    }
256 +
257 +    return result;
258 +  }
259 +
260 +  template<typename ElemType>
261 +  Polynomial<ElemType> operator *( const ElemType v, const Polynomial<ElemType>& p) {
262 +    typename Polynomial<ElemType>::const_iterator i;
263 +    Polynomial<ElemType> result;
264 +    
265 +    for (i = p.begin(); i !=p.end(); ++i) {
266 +        result.addCoefficient( i->first , i->second * v);
267 +    }
268 +
269 +    return result;
270 +  }
271 +  
272    /**
273     * Generates and returns the sum of two given Polynomials.
274     * @param p1 the first polynomial

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines