% Problem 9.17
%clear
%  System model
num=[0 0 1 6];
den=conv([1 10],[1 2 2]);
G=[];
P=[];
Wg=[];
Wp=[];
k=[];
for K=10:10:100,
    [Gm,Pm,Wcg,Wcp] = margin(K*num,den);
    G=[G Gm];
    P=[P Pm];
    Wg=[Wg Wcg];
    Wp=[Wp Wcp];
    k=[k K];
end
i=1:10; i=i';
subplot(221)
plot(i,P)
grid
xlabel('(a) K*10')
ylabel('phase margin')
r=rlocus(num,den,k);
subplot(222)
plot(i,r(:,1))
grid
xlabel('(b) K*10')
ylabel('Re(p1)')
subplot(223)
plot(i,real(r(:,2)))
grid
xlabel('(c) K*10')
ylabel('Re(p2), Re(p3)')
subplot(224)
rlocus(num,den,k)
axis([-10 1 -10 10])
grid