I want to implement a function in java that finds the null points of the sinus function. I know how to do that but I do not really understand the following definition of that problem:
Implement a function that searches for null points in the sinus function in a interval between a and b. The search-interval[lowe开发者_JAVA百科r limit, upper limit] should be halved until lower limit and upper limit are less then 0.0001 away from each other.
Why halving the interval? Any ideas?
Sounds like you are being asked to implement a binary search and you probably require that |b-a| < pi
so there is a unique root in the interval. Btw these are called "sine" and "root" (or "zero") in English.
The idea is that the function (sine) evaluated at the endpoints of your interval will give one positive answer and one negative answer (if both are positive or both are negative, then it fails). Because sine is continuous, there must be a point with value zero in between (intermediate value theorem). Check the midpoint of your interval. If it's positive, collapse from your interval to the interval between the negative-valued endpoint and the midpoint. Otherwise, collapse to the other half. Repeat this until you are within the desired proximity of the zero.
Hint: you can expect at least one root in the interval if
(A) sgn(f(lower_limit) != sgn(f(upper_limit))
If this condition A is true: halve the interval, iaw:
{[min,max]} -> {[min, (max-min)/2] , ](max-min)/2,max]}
and check the two sub-intervals.
Just try it out on paper (use the plot, halve the interfals and try to figure out, which interval is a candidate for a "root container")
Sinus is defined by it's frequency. zero crossings are found at periods 0.5 and 1 of sinus. i.e. sin * pi and *2pi for ordinary sin code function. So between A and B, the zero crossings are all points smaller than B larger than A that are equals to the period == 1 and 0.1, using modulus to ignore values like 2, 2.5, etc.
精彩评论