-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrapezoidSolver.java
36 lines (25 loc) · 1.12 KB
/
TrapezoidSolver.java
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
public class TrapezoidSolver {
public static double[] calculateNumericalIntegrationTrapezoid(double numberofPhases, double numberofSteps, double xLowerBound,
double xUpperBound, double yLowerBound, double yUpperBound, NumericalIntegration myHeight) {
//Code for Trapezoid.
double stepSizeX = (xUpperBound - xLowerBound) / numberofSteps;
double stepSizeY = (yUpperBound - yLowerBound) / numberofSteps;
double[] sum = new double[(int) numberofPhases];
double[] Heights = new double[(int) numberofPhases];
for (int i = 0; i < numberofPhases; i++) {
sum[i] = myHeight.calculateHeightDZ(xLowerBound, yLowerBound)[i]
+ myHeight.calculateHeightDZ(xUpperBound, yUpperBound)[i];
}
double xValue = xLowerBound;
double yValue = yLowerBound;
for (int i = 1; i < (numberofSteps-1); i++) {
sum[0] = sum[0] + 2.0 * myHeight.calculateHeightDZ(xValue, yValue)[0];
sum[1] = sum[1] + 2.0 * myHeight.calculateHeightDZ(xValue, yValue)[1];
xValue = xValue + stepSizeX;
yValue = yValue + stepSizeY;
}
Heights[0] = (stepSizeX / 2) * sum[0];
Heights[1] = (stepSizeY / 2) * sum[1];
return Heights;
}
}