-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
64 lines (46 loc) · 1.97 KB
/
main.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
#include <iostream>
#include "parallel_series.hpp"
int main() {
ParallelSeries resistor;
resistor.onSeries = [](double left, double right) -> double {
return left + right;
};
resistor.onParallel = [](double left, double right) -> double {
return (left != 0 && right != 0) ? (1 / (1/left + 1/right)) : 0;
};
// result 3
resistor.expr = "2 + 2 || 2"; // same as 2 + (2 || 2)
/*"//" == "||" */
//resistor.expr = "2 // (2 + 2)"; // result 1.333
double r = resistor.solve();
printf("\nresistor = %f\n", r);
Delta resistorDelta = {.a=12.0, .b=18.0, .c=6.0};
Star resistorStar = resistor.deltaStarTransform(resistorDelta);
printf("\nresistor Delta(%f, %f, %f) =\n Star(%f, %f, %f) = c + (a || b) = %f\n",
resistorDelta.a, resistorDelta.b, resistorDelta.c,
resistorStar.a, resistorStar.b, resistorStar.c,
resistor.onSeries(resistorStar.c, resistor.onParallel(resistorStar.a, resistorStar.b))
);
resistor.reset();
resistor.expr = "2k + 2k || 2kilo"; // prefixes -> 2000 + 2000 || 2000
printf("\nprefixes = %.20lf\n", resistor.solve()); // result 3000
ParallelSeries capacitor;
capacitor.onSeries = [](double left, double right) -> double {
return (left != 0 && right != 0) ? (1 / (1/left + 1/right)) : ((left > right) ? left : right);
};
capacitor.onParallel = [](double left, double right) -> double {
return (left != 0 && right != 0) ? (left + right) : 0;
};
// result 1.3333
capacitor.expr = "2 + 2 // 2";
double c = capacitor.solve();
printf("\ncapacitor = %f\n", c);
Delta capacitorDelta = {.a=12.0, .b=18.0, .c=6.0};
Star capacitorStar = capacitor.deltaStarTransform(capacitorDelta);
printf("\ncapacitor Delta(%f, %f, %f) =\n Star(%f, %f, %f) = c + (a || b) = %f\n",
capacitorDelta.a, capacitorDelta.b, capacitorDelta.c,
capacitorStar.a, capacitorStar.b, capacitorStar.c,
capacitor.onSeries(capacitorStar.c, capacitor.onParallel(capacitorStar.a, capacitorStar.b))
);
return 0;
}