w=logspace(-1,1,100);
num=760*conv([1 0.438],[1 4.38]);
%num=760*[0.1559 0.05636];
den=conv([1 14 40],conv([1 0.0286],[1 67.0812]));
%den=conv([1 14 40],[1 0.05636]);
[mag,phase]=bode(num,den,w);
magdB=20*log10(mag);
T=0.5
w1=w*180/pi;
dph=-T*w1';
phase05=phase+dph;
[Gm,Pm,Wcp,Wcg]=margin(mag,phase05,w);
fprintf('\n\nStability margins for system with desired ess:\n\n')
fprintf('Gain Margin              = %f dB\n',20*log10(Gm))
fprintf('Phase Margin             = %f degrees\n',Pm)
fprintf('Gain Crossover Frequency = %f rad/sec\n',Wcg)
fprintf('Phase Crossover Frequency= %f rad/sec\n',Wcp)

subplot(211)
semilogx(w,magdB)
grid
xlabel('Frequency (rad/sec)')
ylabel('Gain dB')
subplot(212)
semilogx(w,phase05)
grid
xlabel('Frequency (rad/sec)')
ylabel('Phase deg')
%print -deps sol9_11e