Created
June 3, 2020 17:06
-
-
Save 71m024/a2fff89f97d07cc370a26908772fca94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Euler { | |
public static void main(String[] args) { | |
print(euler(1, 2, 2)); | |
print(euler(1, 2, 1)); | |
print(euler(1, 2, 0.1)); | |
print(euler(1, 2, 0.01)); | |
print(euler(1, 2, 0.001)); | |
print(euler(1, 2, 0.0001)); | |
print(euler(1, 2, 0.00001)); | |
} | |
private static void print(double y) { | |
System.out.println(String.format("y: %s", y)); | |
} | |
private static double euler(double y, double t, double h) { | |
for (double ti = 0; ti < t; ti += h) { | |
double yAbl = yAbl(y, ti); | |
y += h * yAbl; | |
} | |
return y; | |
} | |
private static double yAbl(double y, double t) { | |
return Math.sqrt(y + t); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment