%% Grid Open-Loop and Closed-Loop Responses of Uncertain System
% Create two uncertain real parameters gamma and tau. The nominal value of gamma is 4 and its range is 3 to 5. The nominal value of tau is 0.5 and its value can vary by +/- 30 percent.

gamma = ureal('gamma',4); 
tau = ureal('tau',.5,'Percentage',30);

%
% These uncertain parameters are used to construct an uncertain transfer function p. An integral controller, c, is synthesized for the plant p based on the nominal values of gamma and tau. The uncertain closed-loop system clp is formed.

p = tf(gamma,[tau 1]); 
KI = 1/(2*tau.Nominal*gamma.Nominal); 
c = tf(KI,[1 0]); 
clp = feedback(p*c,1);

%
% The figure below shows the open-loop unit step response (top plot) and closed-loop response (bottom plot) for a grid of 20 values of gamma and tau.

subplot(2,1,1); step(gridureal(p,20),6) 
title('Open-loop plant step responses') 
subplot(2,1,2); step(gridureal(clp,20),6)

% The plot illustrates the low-frequency closed-loop insensitivity achieved by the PI control system.
% Copyright 2015 The MathWorks, Inc.