clear all;
close all;
L2 = tf(3,[1 0])*tf(1,[1 1])*tf(1,[1,2]);
figure(2);
w = logspace(log10(0.6),2,1000);
[s_r,s_i] = nyquist(L2,w);

s_r = s_r(:);
s_i = s_i(:);
s_sn = s_r+s_i*i;
s_sp = s_r-s_i*i;

x = (s_r(1):0.1:0);

a = 1;
b = 1.5;
d = asin(s_i(1)/b);
c = s_r(1)/cos(d);
t1 = -90:1:90;
t2 = abs(d*180/pi):1:91;
t3 = -90:1:(d*180/pi+1);

y3 = a*cos(t1*pi/180) + j*b*sin(t1*pi/180);
y4 = c*cos(t2*pi/180) + j*b*sin(t2*pi/180);
y5 = c*cos(t3*pi/180) + j*b*sin(t3*pi/180);

figure(2);
plot(s_sn,'b-','linewidth',2);hold on;
plot(s_sp,'b--','linewidth',2);

plot(y3,'b-.','linewidth',2);
plot(y4,'b-.','linewidth',2);
plot(y5,'b-.','linewidth',2);

plot(-1,0,'r+','linewidth',2);
xlabel('Re','fontsize',16);
ylabel('Im','fontsize',16);
title('Nyquist Diagram','fontsize',16);
set(gca,'YTick',[-5 0 5]);
set(gca,'XTick',[-5 -1 0 5]);
axis([-2 1.5 -1.7 1.7]);

plot([b*j,s_sp(20)],'b>','linewidth',6);
plot([-b*j,s_sn(20)],'b<','linewidth',6);

grid;