%% Sample Responses of Uncertain Control System Model
% This example illustrates how to sample the open and closed-loop response of an uncertain plant model for Monte Carlo analysis.
% Create two uncertain real parameters and an uncertain plant.

gamma = ureal('gamma',4); 
tau = ureal('tau',.5,'Percentage',30); 
P = tf(gamma,[tau 1]);

%
% Create an integral controller based on the nominal values of plant uncertainties.

KI = 1/(2*tau.Nominal*gamma.Nominal); 
C = tf(KI,[1 0]);

%
% Now create an uncertain closed-loop system.

CLP = feedback(P*C,1);

%
% Sample the plant at 20 values, distributed uniformly about the tau and gamma parameter cube.

[Psample1D,Values1D] = usample(P,20); 
size(Psample1D)

%
% This sampling returns an array of 20 state-space models, each representing the closed-loop system within the uncertainty.
% Now sample the plant at 10 values of tau and 15 values of gamma.

[Psample2D,Values2D] = usample(P,'tau',10,'gamma',15); 
size(Psample2D)

%
% Plot the step responses of the 1-D sampled plant.

subplot(2,1,1); 
step(Psample1D)

%
% Evaluate the uncertain closed-loop model at the same values using usubs, and plot the step response.

subplot(2,1,2); 
step(usubs(CLP,Values1D))

% Copyright 2015 The MathWorks, Inc.