Now we can consider the problem of implementing the body of the loop. As
with any loop body, we must make sure that it will eventually make the loop
condition become false so that the loop can terminate. The behavior of the
loop body, in fact, is determined by the bisection method that we are
implementing. Recall how each iteration of the bisection method works:
- Let ave denote the average of pos and neg.
- If f(ave) is negative, reset neg to ave.
- Otherwise, reset pos to ave.
It looks like the body of the while loop will contain a statement to do the
averaging as well as an if statement to reset neg or pos
as appropriate. What does our implementation look like now?
Click here for the answer
Joseph L. Zachary
Hamlet Project
Department of Computer Science
University of Utah