%% Compute Controller Performance and Sensitivity
% Define a third-order plant model with three manipulated variables and two controlled outputs.

plant = rss(3,2,3);
plant.D = 0;

%
% Create an MPC controller for the plant.

MPCobj = mpc(plant,1);

%
% Specify an integral absolute error performance function and set the performance weights.

PerfFunc = 'IAE';
PerfWts.OutputVariables = [1 0.5];
PerfWts.ManipulatedVariables = zeros(1,3);
PerfWts.ManipulatedVariablesRate = zeros(1,3);

%
% Define a 20 second simulation scenario with a unit step in the output 1 setpoint and a setpoint of zero for output 2.

Tstop = 20;
r = [1 0];

%
% Define the nominal values of the manipulated variables to be zeros.

utarget = zeros(1,3);

%
% Calculate the performance metric, J, and sensitivities, sens, for the specified controller and simulation scenario.

[J,sens] = sensitivity(MPCobj,PerfFunc,PerfWts,Tstop,r,[],[],utarget);

% Copyright 2012 The MathWorks, Inc.