function [X0, MV0, Slack0, info] = znlmpc_computeInfo(coredata, X, U, e, cost, ExitFlag, iter, hOutputFcn, parameters)
% compute optimal moves, initial guess for next interval and other info

%   Author: N. L. Ricker, R. Chen
%   Copyright 1986-2018 The MathWorks, Inc.

%#codegen
%% return initial guess
MV0 = U(2:coredata.p+1,coredata.imv);
X0 = X([3:coredata.p+1 coredata.p+1],:);
Slack0 = max(0,e);
%% return info structure
if nargout > 3
    % Calculate outputs
    p = coredata.p;
    ny = coredata.ny;
    Y = zeros(p+1,ny);
    if isa(hOutputFcn,'function_handle')
        for k = 1:p+1
            yk = hOutputFcn(X(k,:)',U(k,:)',parameters{:});
            Y(k,:) = yk(:)';
        end
    else
        Y = X;
    end
    % Info
    info = struct('MVopt', U(:,coredata.imv), ...
                  'Xopt', X, ...
                  'Yopt', Y, ...
                  'Topt', coredata.Ts*(0:coredata.p)', ...
                  'Slack', e, ...
                  'ExitFlag', ExitFlag, ...
                  'Iterations', iter, ...
                  'Cost', cost);
end