function [x_next, counter, x_values] = Newton_for_comparison(f, df, imax, tol, x_guess)
    x_next = x_guess;
    x_values = [];  % Array to store all root approximations

    for counter = 1:imax
        x_values = [x_values, x_next];  % Store each root approximation
        x_prev = x_next;
        x_next = x_prev - f(x_prev) / df(x_prev);  % Newton-Raphson step
        
        if abs(f(x_next)) < tol
            break;
        end
    end
end
