% function to apply Newton's method to a function
% derivative must be provided

function [y,k] = newton(f,fprime,x)
k = 0;
xprev=x+1;
while abs(x - xprev) > eps*abs(x)
xprev = x;
x = x - f(x)/fprime(x);
k = k + 1;
[k,x]
end
y=x;
return;