%% Set up the transfer function
s = tf('s');
G = 1 / (s^2 + 20*s + 2);
pole(G)

%% Find the poles as a function of K

kp = 0:1000;
poles = zeros(2, length(kp));

poles(1, :) = (-20 + sqrt(400 - 4*(2+kp)))/2;
poles(2, :) = (-20 - sqrt(400 - 4*(2+kp)))/2;

% Could also do roots([...]) or pole(H)

plot(real(poles(1, :)), imag(poles(1, :)), ... 
     real(poles(2, :)), imag(poles(2, :)));

% Woo 3D!
% plot3(real(poles(1, :)), imag(poles(1, :)), kp, ... 
%      real(poles(2, :)), imag(poles(2, :)), kp);

% Plot real and imaginary vs kp
% figure(1);
% plot(kp, poles(1, :), kp, poles(2, :));
% figure(2);
% plot(kp, imag(poles(1, :)), kp, imag(poles(2, :)));
% step(G);

%% Plot zeta = 0.5

rlocus(G)
hold on;
plot([0, -10], [0, 10*sqrt(3)]); % Line for zeta=0.5

rlocfind(G)

