Skip to content

Instantly share code, notes, and snippets.

@cbruegg
Last active November 19, 2015 21:59
Show Gist options
  • Save cbruegg/b24394092a1b50b5ef4c to your computer and use it in GitHub Desktop.
Save cbruegg/b24394092a1b50b5ef4c to your computer and use it in GitHub Desktop.
public static final double EPSILON = 0.00001;
public static double nullstelle2(double ug, double og) {
while (og - ug >= EPSILON) {
double ugErsteHaelfte = ug;
double ogErsteHaelfte = ug + (og - ug) / 2;
double ugZweiteHaelfte = ogErsteHaelfte;
double ogZweiteHaelfte = og;
if (Math.sin(ugErsteHaelfte) * Math.sin(ogErsteHaelfte) <= 0) {
ug = ugErsteHaelfte;
og = ogErsteHaelfte;
} else {
ug = ugZweiteHaelfte;
og = ogZweiteHaelfte;
}
}
double avg = avg(ug, og);
double sin = Math.sin(avg);
System.out.println("Sin: " + sin);
return avg;
}
private static double avg(double ug, double og) {
return (og + ug) / 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment