Header;
%weights
ywt=1;
uwt=.1;
% horizon
hM=5;  % input
hP=10; % prediction
% simulation time
tend = 200;
% constraints
umin = 0;  
umax = 4; 
% no constraints
Kmpc=mpccon(mod,ywt,uwt,hM,hP);
[yunc,uunc]=mpcsim(mod,mod,Kmpc,tend,1,[-Inf,Inf,Inf]);

% Part 3.1 imposing constraints 
% by using mpccon, the optimization problem is solved without constraints
% constraints are not imposed until simulation
Kmpc=mpccon(mod,ywt,uwt,hM,hP);
[ycon,ucon]=mpcsim(mod,mod,Kmpc,tend,1,[umin,umax,Inf]);

% Part 3.2 imposing constraints with hard bounds on manipulated variables
% by using cmpc
ulim = [umin umax inf]; % ulim = [umin umax max_delta_u]
r = 1;
% [yp,u]=cmpc(plant, model,ywt,uwt,M,P,tend,r,ulim,ylim,...)
[ycmpc,ucmpc]=cmpc(mod,mod,ywt,uwt,hM,hP,tend,r,ulim);

plot_MPC3;



