%% Simulate MPC Control with Plant Model Mismatch
% Simulate the MPC control of a multi-input, multi-output (MIMO) system with a mismatch between the predicted and actual plant models. The system has two manipulated variables, two unmeasured disturbances, and two measured outputs.
% Define the predicted plant model.

p1 = tf(1,[1 2 1])*[1 1;0 1];
plantPredict = ss([p1 p1]);
plantPredict.InputName = {'mv1','mv2','umd3','umd4'};

%
% Specify the MPC signal types.

plantPredict = setmpcsignals(plantPredict,'MV',[1 2],'UD',[3 4]);

%
% Create the MPC controller.

mpcobj = mpc(plantPredict,1,40,2);

%
% Define the unmeasured input disturbance model used by the controller.

distModel = eye(2,2)*ss(-0.5,1,1,0);
mpcobj.Model.Disturbance = distModel;

%
% Define an actual plant model which differs from the predicted model and has unforeseen unmeasured disturbance inputs.

p2 = tf(1.5,[0.1 1 2 1])*[1 1;0 1];
plantActual = ss([p2 p2 tf(1,[1 1])*[0;1]]);
plantActual = setmpcsignals(plantActual,'MV',[1 2],'UD',[3 4 5]);

%
% Configure the unmeasured disturbance and output reference trajectories.

dist = ones(1,3);
refs = [1 2];

%
% Create and configure a simulation option set.

options = mpcsimopt(mpcobj);
options.UnmeasuredDisturbance = dist;
options.Model = plantActual;

%
% Simulate the system.

sim(mpcobj,20,refs,options)

% Copyright 2015 The MathWorks, Inc.