mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-23 20:44:39 +08:00
Remove unnecessary code (#4141)
This commit is contained in:
@ -26,22 +26,14 @@ public class EulerMethod {
|
||||
BiFunction<Double, Double, Double> exampleEquation1 = (x, y) -> x;
|
||||
ArrayList<double[]> points1 = eulerFull(0, 4, 0.1, 0, exampleEquation1);
|
||||
assert points1.get(points1.size() - 1)[1] == 7.800000000000003;
|
||||
points1.forEach(point ->
|
||||
System.out.println(
|
||||
String.format("x: %1$f; y: %2$f", point[0], point[1])
|
||||
)
|
||||
);
|
||||
points1.forEach(point -> System.out.printf("x: %1$f; y: %2$f%n", point[0], point[1]));
|
||||
|
||||
// example from https://en.wikipedia.org/wiki/Euler_method
|
||||
System.out.println("\n\nexample 2:");
|
||||
BiFunction<Double, Double, Double> exampleEquation2 = (x, y) -> y;
|
||||
ArrayList<double[]> points2 = eulerFull(0, 4, 0.1, 1, exampleEquation2);
|
||||
assert points2.get(points2.size() - 1)[1] == 45.25925556817596;
|
||||
points2.forEach(point ->
|
||||
System.out.println(
|
||||
String.format("x: %1$f; y: %2$f", point[0], point[1])
|
||||
)
|
||||
);
|
||||
points2.forEach(point -> System.out.printf("x: %1$f; y: %2$f%n", point[0], point[1]));
|
||||
|
||||
// example from https://www.geeksforgeeks.org/euler-method-solving-differential-equation/
|
||||
System.out.println("\n\nexample 3:");
|
||||
@ -55,11 +47,7 @@ public class EulerMethod {
|
||||
exampleEquation3
|
||||
);
|
||||
assert points3.get(points3.size() - 1)[1] == 1.1116729841674804;
|
||||
points3.forEach(point ->
|
||||
System.out.println(
|
||||
String.format("x: %1$f; y: %2$f", point[0], point[1])
|
||||
)
|
||||
);
|
||||
points3.forEach(point -> System.out.printf("x: %1$f; y: %2$f%n", point[0], point[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,11 +71,7 @@ public class EulerMethod {
|
||||
"stepSize should be greater than zero"
|
||||
);
|
||||
}
|
||||
double yNext =
|
||||
yCurrent +
|
||||
stepSize *
|
||||
differentialEquation.apply(xCurrent, yCurrent);
|
||||
return yNext;
|
||||
return yCurrent + stepSize * differentialEquation.apply(xCurrent, yCurrent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user