You can also get the files using the command:
cp /home/cheung/teaching/web/170/Projects/hw8/Handouts/* ~/cs170/hw8
In the remainder of the homework description, I will assume that you have saved these file in your ~/cs170/hw8 directory.
public class MathToolBox { public double f(double x) { return(x); } /** * solveEquation(double a, double b) */ public double solveEquation(double a, double b) { double leftPoint, rightPoint, midPoint; // Interval points double y_leftPoint, y_rightPoint, y_midPoint; // Function values /* --------------------------------------------------- Sanity check: sign f(a) and f(b) must be different --------------------------------------------------- */ if ( (f(a) > 0 && f(b) > 0) || (f(a) < 0 && f(b) < 0) ) { System.out.println("Error: interval not guaranteed to contain a zero"); return(0); // We need to return something.... } /* --------------------------------------------------- The Bisection Algorithm --------------------------------------------------- */ leftPoint = a; rightPoint = b; while ( rightPoint - leftPoint > EPSILON ) { midPoint = (leftPoint + rightPoint)/2.0; // Find the middle y_midPoint = f(midPoint); y_rightPoint = f(rightPoint); if ( (y_midPoint < 0 && y_rightPoint < 0) || (y_midPoint > 0 && y_rightPoint > 0) ) { rightPoint = midPoint; } else { leftPoint = midPoint; } } return (leftPoint + rightPoint)/2.0; } public static final double EPSILON = 0.00000001; // Minimum accuracy } |
Except that:
You did not receive the source code for the MathToolBox and you do NOT need it.
So, do NOT try to write the MathToolBox class using the above text.
You do NOT need to do anything with the MathToolBox class except for having a copy of the program MathToolBox.class in your project directory.
x^{5} - 3 x^{2} - 245 = 0
x^{5} - 3 x^{2} - 245 = 0
You must assign the asnwer to the variable ans that is (already) defined. The value of this variable will be printed for grading purposes.
/home/cs170001/turnin ~/cs170/hw8/hw8.java hw8 /home/cs170001/turnin ~/cs170/hw8/Solve.java hw8a
You must turn in the file with the correct associated code !