function J = computeCost(X, y, theta)
    m = length(y);
    h = X * theta;
    J = (1 / (2*m)) * sum((h - y).^2);
end

function theta_path = gradientDescent(X, y, alpha, num_iterations)
    m = length(y);
    theta = zeros(2,1);
    theta_path = zeros(2, num_iterations + 1);
    theta_path(:,1) = theta;
    
    for iter = 1:num_iterations
        h = X * theta;
        errors = h - y;
        delta = (1/m) * X' * errors;
        theta = theta - alpha * delta;
        theta_path(:,iter+1) = theta;
    end
end
