package Newton; public class TestNewton { static void Test(Function f, double start) { Newton n = new Newton(0.0000001); double x = n.FindRoot(f, start); f.print(x); System.out.println(" = " + f.evaluate(x)); } public static void main (String[] args) { double c[] = {-1,0,2}; Function p = new Polynomial(c); Test(p, 0.5); Test(new Wave(), 0.5); Test(new Wave(), 3.5); Test(new Square(), 2); } } /* expected output (doesnt need to be exactly this) -1.0 * (0.7071067811873449)^0 + 2.0 * (0.7071067811873449)^2 = 2.255307052223543E-12 sin(-3.9269908169830705) + cos(-3.9269908169830705) = -5.898725952135919E-12 sin(2.3561944897962763) + cos(2.3561944897962763) = 5.601256125586929E-10 (2.44145622209259E-4)^2 = 5.960708484394624E-8 */