101 |
|
} |
102 |
|
|
103 |
|
/** |
104 |
+ |
* Set the coefficent of the specified exponent, if the coefficient is already there, it |
105 |
+ |
* will be overwritten. |
106 |
|
* @param exponent exponent of a term in this Polynomial |
107 |
|
* @param coefficient multiplier of a term in this Polynomial |
108 |
|
*/ |
109 |
|
|
110 |
|
void setCoefficient(int exponent, const ElemType& coefficient) { |
111 |
|
polyPairMap_.insert(PolynomialPairMap::value_type(exponent, coefficient)); |
112 |
+ |
} |
113 |
+ |
|
114 |
+ |
/** |
115 |
+ |
* Set the coefficent of the specified exponent. If the coefficient is already there, just add the |
116 |
+ |
* new coefficient to the old one, otherwise, just call setCoefficent |
117 |
+ |
* @param exponent exponent of a term in this Polynomial |
118 |
+ |
* @param coefficient multiplier of a term in this Polynomial |
119 |
+ |
*/ |
120 |
+ |
|
121 |
+ |
void addCoefficient(int exponent, const ElemType& coefficient) { |
122 |
+ |
PolynomialIterator i = find(exponent); |
123 |
+ |
|
124 |
+ |
if (i != end()) { |
125 |
+ |
i->second += coefficient; |
126 |
+ |
} else { |
127 |
+ |
setCoefficient(exponent, coefficient); |
128 |
+ |
} |
129 |
|
} |
130 |
|
|
131 |
+ |
|
132 |
|
/** |
133 |
|
* Returns the coefficient associated with the given power for this Polynomial. |
134 |
|
* @return the coefficient associated with the given power for this Polynomial |
180 |
|
int coefficient; |
181 |
|
|
182 |
|
for (i = p1.begin(); i !=p1.end(); ++i) { |
183 |
< |
for (j = p1.begjn(); j !=p1.end(); ++j) { |
183 |
> |
for (j = p1.begin(); j !=p1.end(); ++j) { |
184 |
|
exponent = i->first + j->first; |
185 |
|
coefficient = i->second * j->second; |
186 |
|
k = p->find(exponent); |