%% Sensitivity of Disk-Based Margins to Gain Increase and Decrease
% By default, diskmargin computes a symmetric gain margin, with gmin = 1/gmax, and an associated phase margin. In some systems, however, loop stability may be more sensitive to increases or decreases in open-loop gain. Use the eccentricity parameter E to examine this sensitivity.
% Compute the disk margin and associated disk-based gain and phase margins for a SISO transfer function, at three values of E. Negative E biases the computation toward gain decrease. Positive E biases toward gain increase.

L = tf(25,[1 10 10 10]);
DMdec = diskmargin(L,-2);
DMbal = diskmargin(L,0);
DMinc = diskmargin(L,2); 
DGMdec = DMdec.GainMargin
DGMbal = DMbal.GainMargin
DGMinc = DMinc.GainMargin  

%
% Put together, these results show that in the absence of phase variation, stability is maintained for relative gain variations between 0.4 and 1.72. To see how the phase margin depends on these gain variations, plot the stable ranges of gain and phase variations for each diskmargin result.

diskmarginplot([DGMdec;DGMbal;DGMinc])
legend('E = -2','E = 0','E = 2')
title('Stable range of gain and phase variations')

% This plot shows that the feedback loop can tolerate larger phase variations when the gain decreases. In other words, the loop stability is more sensitive to gain increase. Although E = –2 yields a phase margin as large as 30 degrees, this large value assumes a small gain increase of less than 3 dB. However, the plot shows that when the gain increases by 4 dB, the phase margin drops to less than 15 degrees. By contrast, it remains greater than 30 degrees when the gain decreases by 4 dB.
% Thus, varying the eccentricity E can give a fuller picture of sensitivity to gain and phase uncertainty. Unless you are mostly concerned with gain variations in one direction (increase or decrease), it is not recommended to draw conclusions from a single nonzero value of E. Instead use the default E = 0 to get unbiased estimates of gain and phase margins. When using nonzero values of E, use both positive and negative values to compare relative sensitivity to gain increase and decrease.
%
% Copyright 2019 The MathWorks, Inc.
%