function r = newton(fx, fxprime, x0, tol)

x = x0;
xnew = x - fx(x)/fxprime(x);
err = abs(xnew - x);
x = xnew;

while err > tol
   xnew = x - fx(x)/fxprime(x);
   err = abs(xnew - x);
   x = xnew;
end

r = xnew;