This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have to write a method that calculates the root of a polynomial. But that root has to be found using binary search. The method specifications are write a method which returns a double value which is the root of the polynomial. The method's parameters are the polynomial, a double value x, double value z and a double value epsilon.
Precondition : epsilon is greater than zero.
and f(x) <= 0 <= f(z)
We have to find a value y between x and z, where f(y) = 0, which is the root of polynomial. The difference between return value and real root is no more than epsilon.
What I do not understand about this problem is how can a search for one double number between two double numbers using binary search.
Here two of my methods, the evaluate method and finding the root on which I am working on:
public double evaluate(double x)
double p = 0;
for (int i = degree; i >= 0; i--)
p = coef[i] + (x * p);