Last active
November 19, 2015 21:59
-
-
Save cbruegg/b24394092a1b50b5ef4c 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 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