%% Check Robustness to Gain and Phase Variations
% The requirement that a closed-loop system is robust against a particular amount of gain and phase uncertainty is equivalent to saying that the system has that amount of gain and phase margin. You can therefore use a umargin block to check the gain and phase margins of a system that also requires robustness against other types of uncertainty. To do so, capture your required disk margins in a umargin block, and use robstab to check robust stability against all uncertainty modeled in the system.
% Consider the following closed-loop system with parameter uncertainty.

k = ureal('k',10,'Percent',40);
G = tf(18,[1 k k]);
C = pid(1,2);
CL = feedback(G*C,1);

% robstab shows that the system is robust against the modeled uncertainty. In fact, the system remains stable up two a little more than twice the modeled uncertainty.

stabmarg = robstab(CL)

%
% Suppose that you also require the system to tolerate gain increase or decrease of up to 50% and phase variation of up to ±20° at the plant input. To check whether the system has these margins, create a umargin block that models these variations and insert it into the closed-loop model.

DGM = getDGM(1.5,20,'tight');
F = umargin('F');
Gf = G*F;
CLf = feedback(Gf*C,1);

stabmarg = robstab(CLf)

% This result shows that in addition to robust stability against parameter variation, the feedback loop also maintains the desired gain and phase margins for all modeled values of k (actually for about 9% more than the modeled range of k).
% You can also use the equivalence between disk margins and robust stability to gain and phase variations to design a robust controller that satisfies certain gain and phase margins.  For examples, see Design Robust Controller With Specified Gain and Phase Margins and Robust Controller for Spinning Satellite.
%
% Copyright 2019 The MathWorks, Inc.