function [final_result, n] = trapezoidal_converge_6_decimal(f, a, b)

    % Analytical result (log(2)) for comparison
    analytical_result = log(2);
    
    % Initialize variables
    n = 1; % initial number of intervals
    final_result = 0; % to store the final result
    accuracy_threshold = 1e-6; % desired accuracy for 6 decimal places
    
    % Loop until the result is accurate to 6 decimal places as the analytical result
    while true
        h = (b - a) / n; % width of each interval

        % Trapezoidal Rule
        x_trap = a:h:b; % x values for trapezoidal rule
        current_result = (h / 2) * (f(a) + f(b) + 2 * sum(f(x_trap(2:end-1))));
        
        % Check if current result matches analytical result to 6 decimal places
        if round(current_result, 6) == round(analytical_result, 6)
            final_result = current_result;
            break; % stop when the result is accurate to 6 decimal places
        end

        % Update for next iteration
        n = n + 1; % increase the number of intervals
    end

    % Display the result and the number of intervals needed
    fprintf('Final result: %.6f\n', final_result);
    fprintf('Number of intervals needed: %d\n', n);
end
