-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpression.cpp
70 lines (55 loc) · 1.16 KB
/
Expression.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Expression.h"
Expression::Expression()
{
}
void Expression::add(variable v) {
variables.push_back(v);
}
bool Expression::remove(variable v) {
std::vector<variable>::iterator iter;
/*iter = std::find(variables.begin(), variables.end(), v);
if (iter != variables.end()) {
variables.erase(iter);
return true;
}
else {
return false;
}*/
return true;
}
void Expression::clear() {
variables.clear();
}
Expression Expression::PartialDifferentiation(variable::symbol s) {
Expression resultEquation;
for each(variable v in variables) {
variable tempv = v.PartialDifferentiation(s);
if(tempv.coefficient != 0.0)
resultEquation.add(tempv);
}
return resultEquation;
}
std::string Expression::toString() {
std::string s = "";
for each (variable v in variables) {
if (v.coefficient > 0)
s += "+";
s += v.toString();
s += " ";
}
return s;
}
double Expression::getConstant() {
for each(variable v in variables) {
if (v.isConstant())
return v.coefficient;
}
return 0.0;
}
double Expression::getValue(double x, double y) {
double result = 0;
for each(variable v in variables) {
result += v.getValue(x, y);
}
return result;
}