function [x, t, e] = newtons(g, x0, TOL, N0)
    % Initial step size based on tolerance
    h = sqrt(eps); % Square root of machine epsilon

    i = 1;
    tic;
    while (i <= N0)
        g_val = feval(g, x0); % Evaluate g(x0)

        % Richardson extrapolation with central difference formula
        g_prime_val_h1 = (feval(g, x0 + h) - feval(g, x0 - h)) / (2 * h);
        g_prime_val_h2 = (feval(g, x0 + h/2) - feval(g, x0 - h/2)) / h;
        g_prime_val = (4*g_prime_val_h2 - g_prime_val_h1) / 3;

        x = x0 - g_val / g_prime_val; % Newton's method formula
        if (abs(x - x0) < TOL)
            t = toc;
            e = 5*(i - 1);
            return
        end



        i = i + 1;
        x0 = x;
    end
    x = NaN;
    t = NaN;
    e = NaN;
end

