% newton.m: Does Newton's method on given function.
% Usage: newton('f', 'df', eps, a).  eps is tolerance, "a" initial guess
function c = newton(f, df, eps, b)

%Treat a as old, b as new
a=b+2*eps;

k = 1;
while abs(b-a)>eps %Dumb termination criterion, but OK for now.
    
    e1 = abs(b-2);
    a = b;
    b = a - f(a)/df(a);
    disp([k,b,b-2,abs(b-2)/e1^2]);
    k = k+1;

end

c=b;