% Generates Fig 3.17
% Computer Controlled Systems (3rd ed)
% Author: B. Wittenmark
% Last edit: 1997-06-29
% Copyright (c) 1996 by K. J. Åström, B. Wittenmark and
% Department of Automatic Control, Lund Institute of
% Technology, Lund, Sweden

clear all; close all;

newplot;clf;
set(gcf,'PaperUnits','centimeters','PaperPosition',[2 2 13 8])
set(gcf,'Units','centimeters','position',get(gcf,'PaperPosition'))

lw=2;

den=[1 -2 1];
num=[0 2 -1];
K=[0:0.01:1,1.1:0.1:20, 500];
[m,n]=size(K);
r=zeros(n,2);

% Plot Unit circle
t=0:.1:6.3;
plot(sin(t),cos(t),'k--')
%axis([-6 2 -2.5 2.5]);
axis([-2.5 1.5 -1 1]);
axis('equal')
hold on

for i=1:n,
  tot=den+K(i)*num;
  r(i,:)=roots(tot)';
end;

plot(r,'k','Linew',lw);
hpl=plot([1 1],[0.015 -0.015],'mx',0.5,0,'mo','Linew',lw);
%title('Fig 3.13');
set(gca,'Fontsize',9,'Fontname','NewCenturySchlbk');
set(gca,'xtick',[-2 -1 0 1 2],'ytick',[-1 0 1]);
set(hpl,'MarkerSize',6)
ylabel('Imaginary axis','Fontname','NewCenturySchlbk','Fontsize',9)
xlabel('Real axis','Fontname','NewCenturySchlbk','Fontsize',9)
%Draw axis
plot([-6 2],[0 0],'k:',[0 0],[-3 3],'k:')
zgrid
arrow2([0.45 0.5],pi);
arrow2([0.45 -0.5],pi);
arrow2([0.25 0],0);
arrow2([-0.25 0],pi);

title('Root locus wrt K of the PD system with T_d = 1.5')
hold off
