% Function for linear interpolation
function temp_estimate = linear_interpolation(x, y, x_query)
    idx_below = find(x < x_query, 1, 'last'); % Index of value below query
    idx_above = find(x > x_query, 1, 'first'); % Index of value above query
    
    if isempty(idx_below) || isempty(idx_above)
        error('Interpolation requires points both below and above the query value.');
    end
    
    % Linear interpolation formula
    x0 = x(idx_below);
    x1 = x(idx_above);
    y0 = y(idx_below);
    y1 = y(idx_above);
    
    temp_estimate = y0 + ((y1 - y0) / (x1 - x0)) * (x_query - x0);
end