function p = newtoneg(p0,tol,Nmax)
%NEWTON'S METHOD: Enter f(x), f'(x), x0, tol, Nmax
f = @(x) x^3 + 4*x^2 - 10;
fp = @(x) 3*x^2 + 8*x;
p = p0 - f(p0)/fp(p0);
i = 1;
while (abs(p - p0) >= tol)
    p0 = p
    p = p0 - f(p0)/fp(p0);
    i = i + 1;
    if (i >= Nmax)
        fprintf('Fail after %d iterations\n',Nmax);
        break
    end
end
end

