You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: max_output_set.m
    path of file: ./repos/quadrotor-pendulum/functions
    
    the code of the file until where you have to start completion: function [H,h] = max_output_set(A,K,u_lim,x_lim)

% Pedro's newest, freshest code on the block

% Input constraints
f1 = u_lim*ones(2*size(K,1),1);

% State constraints
f2 = [x_lim; x_lim];

f = [f1;f2];
s = size(f,1);

%% Algorithm implementation
exit_flag=0;
k=0;

A_in=[];
b = [];

opts = optimoptions('linprog','Display','off');

while exit_flag==0 
    fprintf('\tk = %i \n',k);
    A_in = [A_in; K*A^k; -K*A^k; A^k; -A^k];

    
function [H,h] = max_output_set(A,K,u_lim,x_lim)

% Pedro's newest, freshest code on the block

% Input constraints
f1 = u_lim*ones(2*size(K,1),1);

% State constraints
f2 = [x_lim; x_lim];

f = [f1;f2];
s = size(f,1);

%% Algorithm implementation
exit_flag=0;
k=0;

A_in=[];
b = [];

opts = optimoptions('linprog','Display','off');

while exit_flag==0 
    fprintf('\tk = %i \n',k);
    A_in = [A_in; K*A^k; -K*A^k; A^k; -A^k];
    b = [b; f];
     
    h = [K*A^(k+1); -1*K*A^(k+1); A^(k+1); -1*A^(k+1)];
     
    opt_val = zeros(1,s);
    for i=1:s                
        [~,fval,exit] = linprog(-h(i,:),A_in,b,[],[],[],[],opts);
        if exit == -3
            fval = inf;
        end