package newton;


/** Represents the Newton method.
 * @author Alan Ponte.*/
public class NewtonSolver {
	
	/** Creates a new solver with the Polynoomial P, the 
	 * derivative of the Polynomial, DF, and an initial guess of GUESS.
	 * The solver will run until the TOLERANCE is reached.*/
	public NewtonSolver(Polynomial p, Polynomial df, double guess, double tolerance) {
		_poly = p;
		_guess = guess;
		_df = df;
		_tol = tolerance;
	}
	
	/** Creates a new solver with the Polynoomial P, the 
	 * derivative of the Polynomial, DF, and an initial guess of GUESS.
	 * The solver will run until the TOLERANCE is reached, or the maximum number
	 * of iterations. MAXITER is reached.*/
	public NewtonSolver(Polynomial p, Polynomial df, double guess, double tolerance, int maxIter) {
		_poly = p;
		_guess = guess;
		_df = df;
		_tol = tolerance;
		_maxIter = maxIter;
	}

	/** Returns the tolerance of THIS solver.*/
	public double getTolerance() {
		return _tol;
	}

	/**Returns the result of applying newton's method.*/
	public double solve() {
		int i = 0;
		double p = 0.0;
		while (true) {
			p = _guess - _poly.valueAt(_guess)/_df.valueAt(_guess);
			System.out.println("P-Value: " + p + " itration : " + i);
			if (Math.abs(p - _guess) < _tol) {
				break;
			}
			_guess = p;
			i += 1;
		}
		return p;
	}
	
	private Polynomial _poly;
	private Polynomial _df;
	private double _guess;
	private double _tol;
	private int _maxIter;

}

@@ -1307,16 +1307,40 @@
 p;%0A%09%7D%0A%09%0A
+%09/** THIS Polynomial.*/%0A
 %09private
@@ -1363,77 +1363,226 @@
 y;%0A%09
-private Polynomial _df;%0A%09private double _guess;%0A%09private double _tol;
+%0A%09/** The derivative of THIS Polynomial.*/%0A%09private Polynomial _df;%0A%09%0A%09/** The initial guess.*/%0A%09private double _guess;%0A%09%0A%09/** The allowable tolerance.*/%0A%09private double _tol;%0A%09%0A%09/** The maximum amount of iterations.*/
 %0A%09pr

Update NewtonSolver.java