% Problem 9.4
clear
% Model of magnetic tape control system
A=[0  0.40  0.000   0.00
   0  0.00  0.349   0.00
   0 -5.24 -4.650   2.62
   0  0.00  0.000 -10.00];
B=[0 0 0 10]';
C=[1 0 1 0];
D=0;

% Transfer function
[num,den]=ss2tf(A,B,C,D,1)
for i=1:length(num),
    if num(i) < 1.e-10,
       num(i)=0;
    end
end

% Bode diagram
bode(num,den)

% Gain and phase margins
[Gm,Pm,Wcp,Wcg]=margin(num,den);

% Printing of the results
fprintf('\n\nExisting system parameters are as follows:\n\n')
fprintf('Gain Margin              = %f dB\n\n',20*log10(Gm))
fprintf('Phase Margin             = %f degrees\n\n',Pm)
fprintf('Phase Crossover Frequency = %f rad/sec\n\n',Wcp)
fprintf('Gain Crossover Frequency= %f rad/sec\n\n',Wcg)
