%% Compute Steady-State Gain
% This example shows how to analyze a model predictive controller using  cloffset. This function computes the closed-loop, steady-state gain for each output when a sustained, 1-unit disturbance is added to each output. It assumes that no constraints are active.
% Define a state-space plant model.

A = [-0.0285 -0.0014; -0.0371 -0.1476];
B = [-0.0850 0.0238; 0.0802 0.4462];
C = [0 1; 1 0];
D = zeros(2,2);
CSTR = ss(A,B,C,D);

CSTR.InputGroup.MV = 1;
CSTR.InputGroup.UD = 2;

%
% Create an MPC controller for the defined plant.

MPCobj = mpc(CSTR,1);

%
% Specify tuning weights for the measured output signals.

MPCobj.W.OutputVariables = [1 0];

%
% Compute the closed-loop, steady-state gain for this controller.

DCgain = cloffset(MPCobj)

% DCgain(i,j) represents the gain from the sustained, 1-unit disturbance on output j to measured output i.
% The second column of DCgain shows that the controller does not react to a disturbance applied to the second output. This disturbance is ignored because the tuning weight for this channel is 0.
% Since the tuning weight for the first output is nonzero, the controller reacts when a disturbance is applied to this output, removing the effect of the disturbance (DCgain(1,1) = 0). However, since the tuning weight for the second output is 0, this controller reaction introduces a gain for output 2 (DCgain(2,1) = 2.3272).
% Copyright 2012 The MathWorks, Inc.