function results_trap = evaluate_function(intervals)
    % evaluate_function calculates the integral of f(x) = 1/x over [1, 2]
    % using the trapezoidal rule for the specified intervals.
    %
    % Input:
    %   intervals - Array of numbers of intervals to evaluate.
    %
    % Output:
    %   results_trap - Results from the trapezoidal rule.

    % Define the function
    f = @(x) 1 ./ x;

    % Define the interval
    a = 1; % lower bound
    b = 2; % upper bound

    % Initialize result array
    results_trap = zeros(size(intervals));

    % Loop over the number of intervals
    for i = 1:length(intervals)
        n = intervals(i); % current number of intervals
        h = (b - a) / n; % width of each interval
        
        % Trapezoidal Rule
        x_trap = a:h:b; % x values for trapezoidal rule
        results_trap(i) = (h/2) * (f(a) + f(b) + 2 * sum(f(x_trap(2:end-1))));
    end
end
