%% Obtain Test Results for Multiple Controllers
% Create and review designs for gain-scheduled model predictive controllers for two plant operating conditions.
%
% Define the model parameters.

M1 = 1;
M2 = 5;
k1 = 1;
k2 = 0.1;
b1 = 0.3;
b2 = 0.8;
yeq1 = 10;
yeq2 = -10;

%
% Create plant models for each of the two operating conditions.

A1 = [0 1; -k1/M1 -b1/M1];
B1 = [0 0; -1/M1 k1*yeq1/M1];
C1 = [1 0];
D1 = [0 0];
sys1 = ss(A1,B1,C1,D1);
sys1 = setmpcsignals(sys1,'MV',1,'MD',2);

A2 = [0 1; -(k1+k2)/(M1+M2) -(b1+b2)/(M1+M2)];
B2 = [0 0; -1/(M1+M2) (k1*yeq1+k2*yeq2)/(M1+M2)];
C2 = [1 0];
D2 = [0 0];
sys2 = ss(A2,B2,C2,D2);
sys2 = setmpcsignals(sys2,'MV',1,'MD',2);

%
% Design an MPC controller for each operating condition.

Ts = 0.2;
p = 6;
m = 2;
MPC1 = mpc(sys1,Ts,p,m);
MPC2 = mpc(sys2,Ts,p,m);

controllers = {MPC1,MPC2};

%
% Review the controller designs, and store the test result structures.

for i = 1:2
    results(i) = review(controllers{i});
end

%
% Copyright 2018 The MathWorks, Inc.