Skip to content

Instantly share code, notes, and snippets.

@71m024
Created June 3, 2020 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 71m024/a2fff89f97d07cc370a26908772fca94 to your computer and use it in GitHub Desktop.
Save 71m024/a2fff89f97d07cc370a26908772fca94 to your computer and use it in GitHub Desktop.
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