clear all;
close all;
L4 = tf(5,[1 0])*tf([1 1],[1 -10]);

w = logspace(log10(0.3),3,1000);

[s_r,s_i] = nyquist(L4,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.5;
b = 2;
d = asin(s_i(1)/b);
c = s_r(1)/cos(d);
e = a*s_i(1)/(sqrt(a^2 - s_r(1)^2));
f = asin(s_i(1)/e);
% t1 = -90:1:90;
% t2 = abs(d*180/pi):1:91;
% t3 = -90:1:(d*180/pi+1);
t4 = (-f*180/pi):1:(f*180/pi+1);

y3 = -a*cos(t4*pi/180) + j*e*sin(t4*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(4);
plot(s_sn,'b-','linewidth',2);hold on;
plot(s_sp,'b--','linewidth',2);

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


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',[-10 -1 0 5]);

plot([y3(39),s_sn(450)],'b>','linewidth',3);
plot([y3(100),s_sp(450)],'b<','linewidth',3);

plot(s_sn(100),'bv','linewidth',6);
plot(s_sp(100),'bv','linewidth',6);

axis([-3 1.5 -2 2]);
grid;