%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This is a Matlab file to demonstrate
%the root locus design.
%
%The result shows that a PD controller 
%speeds up transient response, and
%a lead compensator approximates to 
% a PD controller.
%
%The plant model is Gp=10/s(s+1).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%P control:

%gain:
Kp=0.05;

%closed-loop TF
num=[0 0 10*Kp];
den=[1 1 10*Kp];
sys=tf(num,den)

%step response:
step(sys);
grid;

hold on;

%%%%%%%%%%%%%%%%%%%PD control:

Kpd=0.5;
a_pd=3.6;

%closed-loop TF
num1=[0 10*Kpd 10*Kpd*a_pd];
den1=[1 10*Kpd+1 10*Kpd*a_pd];
sys1=tf(num1,den1)

%step response:
step(sys1);

hold on;

%%%%%%%%%%%%%%%%%%%Lead compensation:

K=7.8;
a=3;
b=18;

%closed-loop TF
num2=[0 0 10*K 10*K*a];
den2=[1 b+1 b+10*K 10*K*a];
sys2=tf(num2,den2)

%step response:
step(sys2);

hold off;

