Illustrates how the algorithm is used in 3 examples and prints the results to the console.
(String[] args)
| 24 | * results to the console. |
| 25 | */ |
| 26 | public static void main(String[] args) { |
| 27 | System.out.println("example 1:"); |
| 28 | BiFunction<Double, Double, Double> exampleEquation1 = (x, y) -> x; |
| 29 | ArrayList<double[]> points1 = eulerFull(0, 4, 0.1, 0, exampleEquation1); |
| 30 | assert points1.get(points1.size() - 1)[1] == 7.800000000000003; |
| 31 | points1.forEach(point -> System.out.printf("x: %1$f; y: %2$f%n", point[0], point[1])); |
| 32 | |
| 33 | // example from https://en.wikipedia.org/wiki/Euler_method |
| 34 | System.out.println("\n\nexample 2:"); |
| 35 | BiFunction<Double, Double, Double> exampleEquation2 = (x, y) -> y; |
| 36 | ArrayList<double[]> points2 = eulerFull(0, 4, 0.1, 1, exampleEquation2); |
| 37 | assert points2.get(points2.size() - 1)[1] == 45.25925556817596; |
| 38 | points2.forEach(point -> System.out.printf("x: %1$f; y: %2$f%n", point[0], point[1])); |
| 39 | |
| 40 | // example from https://www.geeksforgeeks.org/euler-method-solving-differential-equation/ |
| 41 | System.out.println("\n\nexample 3:"); |
| 42 | BiFunction<Double, Double, Double> exampleEquation3 = (x, y) -> x + y + x * y; |
| 43 | ArrayList<double[]> points3 = eulerFull(0, 0.1, 0.025, 1, exampleEquation3); |
| 44 | assert points3.get(points3.size() - 1)[1] == 1.1116729841674804; |
| 45 | points3.forEach(point -> System.out.printf("x: %1$f; y: %2$f%n", point[0], point[1])); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * calculates the next y-value based on the current value of x, y and the |