A Java Course Outline
Using the Java By Dissection book
by Ira Pohl and Charlie McDowell

 



Homework 3 - Roots of an Equation

We will write a program to find a zero of the following equation:

F(x) = sin(x) - cos(x).

A simple way to do this is by starting with x = 0, and at intervals of .001 iterate across a range say (0 =< x =< 2), and find the value closest to 0.0, namely F(root) = 0.0 +/- epsilon. So you would write a loop that would evaluate the function and choose the value in this range that gives the best answer numerically. For this range and intervals, we need to evaluate F(x) 2000 times. This method is straightforward to understand program and debug.


Extra Credit

More difficult is to find the root by bisection. This method is more difficult to understand and get correct. If you choose to do the problem this way instead you can get extra credit. In bisection we have a range of values (0 =< x <= 2) and know a root exists in that range and the equation is continuous. Then we also know that F(a)*F(b) < 0, which implies that a rtoot is in this range. We pick the middle of this range (a + b)/2 and evaluate the function there. We decide which endpoint of the range to replace based on the sign of the value of F(x). This becomes a new endpoint. When the two endpoints are close we stop with their midpoint being the computed root.

Which option to undertake depends on your understanding of each method and your ability to program. If the bisection method is difficult for you to understand and write pseudocode for you choose the more elementary and inefficient iterative method.


Feel free to report any site problems to the Webmaster, Debra Dolsberry.