% FILE: ogataExampleRootLocus011119.m
% DATE: 01/11/19 07:31
% AUTH: P.Oh
% DESC: Root Locus plot for closed-loop system

% Ogata Example 7-2 has a unity feedback system 
% The plant G is given by 


%              1.06               1.06
%   G(s) = -------------- = -----------------
%           s(s+1)(s+2)      s^3 + 3s^2 + s

% Under unity feedback, one can derive the CLTF, Gcl as

%                 1.06                1.06
%   Gcl(s) = ---------------- = ---------------------
%            s(s+1)(s+2)+1.06   s^3 + 3s^2 + s + 1.06

% Define OLTF

GNum = [1.06];
GDen = [1 3 1 0];

G = tf(GNum, GDen)

% In factored (i.e. zero and pole) form

zpk(G)

% Display roots for OLTF

roots(GDen)

% Define CLTF

GclNum = [1.06];
GclDen = [1 3 2 1.06];
Gcl = tf(GclNum, GclDen)

% In factored (i.e. zero and pole) form

zpk(Gcl)


% Display roots for CLTF

roots(GclDen)

% Display root locus for OLTF.  Use rlocusplot so can add title etc

handleRootLocusPlot = rlocusplot(G);
plotOptions = getoptions(handleRootLocusPlot);
plotOptions.Title.String = 'Ogata Fig 7-14b; RL for OLTF';
plotOptions.XLim = [-4 2];
plotOptions.YLim = [-3 3];
setoptions(handleRootLocusPlot, plotOptions);


