Root Locus Example #2

MATLAB Code




%         ***** MATLAB Code Starts Here
%

%ROOT_LOCUS_02_MAT

%

fig_size = [232 84 774 624];

olz = [-7;-4;-1]; % open-loop poles, zeros, and gain

olp = [-0.5;-2;-5;-4+j*2;-4-j*2];

K = 8;

%

num = K*real(poly(olz)); % open-loop transfer function

den = real(poly(olp));

%

s1 = -2+j*3; % test point in the s-plane

%

% Magnitude and Phase of the transfer function evaluated

% at s = s1.

%

magns1 = abs(polyval(num,s1));

magds1 = abs(polyval(den,s1));

mags1 = magns1 / magds1;

%

phns1 = unwrap(angle(polyval(num,s1))) * 180/pi;

phds1 = unwrap(angle(polyval(den,s1))) * 180/pi;

phs1 = phns1 - phds1;

%

% Magnitude and Phase of individual poles and zeros

% evaluated at s = s1.

%

for i = 1:length(olz)

magz(i) = abs(polyval([1 -olz(i)],s1));

phz(i) = unwrap(angle(polyval([1 -olz(i)],s1))) * 180/pi;

end

%

for i = 1:length(olp)

magp(i) = abs(polyval([1 -olp(i)],s1));

php(i) = unwrap(angle(polyval([1 -olp(i)],s1))) * 180/pi;

end

%

% Plot the vectors from the poles and zeros of G(s)

% to the point s = s1.

%

figure(1),clf,plot(real(olp),imag(olp),'rx',real(olz),imag(olz),'ro',...

real(s1),imag(s1),'r*',...

[real(olz(1)) real(s1)],[imag(olz(1)) imag(s1)],'m',...

[real(olz(2)) real(s1)],[imag(olz(2)) imag(s1)],'m',...

[real(olz(3)) real(s1)],[imag(olz(3)) imag(s1)],'m',...

[real(olp(1)) real(s1)],[imag(olp(1)) imag(s1)],'b',...

[real(olp(2)) real(s1)],[imag(olp(2)) imag(s1)],'b',...

[real(olp(3)) real(s1)],[imag(olp(3)) imag(s1)],'b',...

[real(olp(4)) real(s1)],[imag(olp(4)) imag(s1)],'b',...

[real(olp(5)) real(s1)],[imag(olp(5)) imag(s1)],'b'),grid,...

xlabel('Real Axis'),ylabel('Imag Axis'),...

title('Poles & Zeros of G(s) Evaluated at s = s_1'),axis('square'),axis([-8 0 -4 4]),...

text(-7.5,3.5,sprintf('MAG_{s1} = %g',mags1)),...

text(-7.5,2.5,sprintf('PH_{s1} = %g',phs1)),text(-1.9,3.2,'s_1'),set(gcf,'Position',fig_size)

%

% Plot the Root Locus of G(s) for K > 0 and K < 0

%

figure(2),clf,root_locus(num,den);title('G(s) Root Locus for K > 0'),...

hold on,plot(real(s1),imag(s1),'r*'),hold off,...

text(-1.7,3.3,'s_1'),set(gcf,'Position',fig_size)

%

figure(3),clf,root_locus(-num,den);title('G(s) Root Locus for K < 0'),...

hold on,plot(real(s1),imag(s1),'r*'),hold off,...

text(-1.7,3.3,'s_1'),set(gcf,'Position',fig_size)

%

% Design two different compensators which will make s = s1 be a

% closed-loop pole for K > 0. The first compensator will have only 1 pole, and

% the second compensator will have 1 pole and 1 zero.

%

phcp1 = 180 + phs1;

pc1 = abs(real(s1)) + imag(s1) / tan(phcp1*pi/180);

denc1 = [1 pc1];

denf1 = conv(den,denc1);

Kc1 = abs(polyval(denf1,s1)) / abs(polyval(num,s1));

%

figure(4),clf,root_locus(num,denf1);title('First Compensated Root Locus for K > 0'),...

hold on,plot(real(s1),imag(s1),'r*'),hold off,...

text(-1.7,3,'s_1'),set(gcf,'Position',fig_size)

%

% Second Compensator

%

pc2 = 3.5;

denc2 = [1 pc2];

denf2 = conv(den,denc2);

%

phcp2 = unwrap(angle(polyval(denc2,s1)))*180/pi;

phcz2 = phcp2 - phcp1;

zc2 = abs(real(s1)) + imag(s1) / tan(phcz2*pi/180);

numc2 = [1 zc2];

numf2 = conv(num,numc2);

Kc2 = abs(polyval(denf2,s1)) / abs(polyval(numf2,s1));

%

figure(5),clf,root_locus(numf2,denf2);title('Second Compensated Root Locus for K > 0'),...

hold on,plot(real(s1),imag(s1),'r*'),hold off,...

text(-1.7,3.3,'s_1'),set(gcf,'Position',fig_size)

%
%         ***** MATLAB Code Stops Here

Click the icon to return to the Dr. Beale's home page