%% Stability Analysis of Zero-Pole-Gain Models
% For this example, create a zero-pole-gain model object sys using the zpk command.

zeros = -2.6;
poles = [0 -0.6+1.1i -0.6-1.1i];
gain = 0.5;
sys = zpk(zeros,poles,gain)

% Next, compute the closed-loop zero-pole-gain model for a unit negative gain and find the poles of the closed-loop zero-pole-gain model object sysFeedback.

sysFeedback = feedback(sys,1);
P = pole(sysFeedback)

% The feedback loop for unit gain is stable since all poles have negative real parts. Checking the closed-loop poles provides a binary assessment of stability. In practice, it is more useful to know how robust (or fragile) stability is. One indication of robustness is how much the loop gain can change before stability is lost. You can use the root locus plot to estimate the range of k values for which the loop is stable.

rlocus(sys)

% Changes in the loop gain are only one aspect of robust stability. In general, imperfect plant modeling means that both gain and phase are not known exactly. Since modeling errors have the most detrimental effect near the gain crossover frequency (frequency where open-loop gain is 0dB), it also matters how much phase variation can be tolerated at this frequency.
% You can display the gain and phase margins on a Bode plot as follows.

bode(sys)
grid

% For a more detailed example, see Assessing Gain and Phase Margins.
% Copyright 2020 The MathWorks, Inc.