% Problem 3.27
disp('Problem 3.27')
disp(' ')
% System model
A=[-11.61 -0.39 27.2 0 0;
   0.01 -16.99 0 0 12.47;
  15.11 0 -53.6 -16.57 71.78;
  -15.36 0 0 -107.2 232.11;
  2.27 60.1 0 2.273 -102.99];

B=[11.12 -2.61 -21.91 -53.5 69.1;
   -12.6 3.36 0 0 0]';

C=[0 0 0 0 1;
   0 1 1 0 0];

D=[0 0;
   0 0];

% Sampling time T=0.1sec
T=0.1
% Discrete-time system
[Ad,Bd]=c2d(A,B,T)
% Transfer function
[num11,den]=ss2tf(Ad,Bd,C,D,1);
[num12,den]=ss2tf(Ad,Bd,C,D,2);
[num21,den]=ss2tf(Ad,Bd,C,D,1);
[num22,den]=ss2tf(Ad,Bd,C,D,2);
disp(' ')
disp('3.27(a) - System transfer function')
printsys(num11,den,'s')
printsys(num12,den,'s')
printsys(num21,den,'s')
printsys(num22,den,'s')

% 3.27(b) - Impulse response
k=50;
subplot(211)
dimpulse(Ad,Bd,C,D,1,k)
grid
[cx,cy]=ginput(1);
text(cx,cy,'y1')
[cx,cy]=ginput(1);
text(cx,cy,'y2')
subplot(212)
dimpulse(Ad,Bd,C,D,2,k)
[cx,cy]=ginput(1);
text(cx,cy,'y1')
[cx,cy]=ginput(1);
text(cx,cy,'y2')
%grid

% 3.26(c)
k=0:1:50;
u=[exp(-T*k')+sin(T*k'),0*k'];
figure(2)
subplot(111)
dlsim(Ad,Bd,C,D,u);
[cx,cy]=ginput(1);
text(cx,cy,'y1')
[cx,cy]=ginput(1);
text(cx,cy,'y2')
grid