I have following challenge:
Implement a function that searches for a null point of the sinus function in a interval between a and b. The search-interval[lower limit, upper limit] should be halved until lower limit and upper limit are less then 0.0001 away from each other.
-
Find a condition to decide in which halved interval the search has to be continued. So after cutting the interval into two intervals we have to choose one to get on with our search.
-
We assume that there is just one zero point in the interval between a and b.

I am struggling with point 1. I already had some questions on that topic that helped me a lot but now I need to implement it in java but it is not working yet.
Here is my code so far:
private static double nullstelle(double a, double b){
double middle = (a + b)/2;
double result = middle;
if(Math.abs(a-b) > 0.0001){
double sin = Math.sin(middle);
if(sin > 0){
result = nullstelle(a, middle);
}else{
result = nullstelle(middle, b);
}
}
return result;
}
I tried to implement using recursion but maybe an other way would be better, I don’t know.
Any ideas?
If there is just one zero point between a and b, that means sign(sin(a)) != sign(sin(b)). In replacing a or b with your mid-point, you’ll need to make sure this remains the case by doing something like this:
with sign(x) defined as