function f = output(X,U,D)

parameters
% Splitting the states
x = X(1:(NC-1)*NT);                    % Liquid compositions from btm to top
M = X((NC-1)*NT+1:NC*NT);              % Liquid hold up from btm to top

% Rearrange elements of composition vector (x) for later use
Iu = reshape(1:(NC-1)*NT,NT,NC-1);
x  = x(Iu);                          

% Inputs
LT = U(1);                             % Reflux
VB = U(2);                             % Boilup

% Disturbances
F  = D(1);                             % Feedrate
qF = D(2);                             % Feed liquid fraction
zF = D(3:end);                         % Feed compositions

% The distillation model
flag = 0; % This flag signals the inclusion of equations for liquid levels. If flag~=0, Simulink is being used and no liquid level is calculated in the code.
model

f = {LT, VB, D, B, x(end,:), x(1,:), L(2:NT), V(1:NT-1), x};

