% Problem 3.29

disp('Problem 3.29')
disp(' ')

% System model
A=[-0.015 -0.0805 -0.0011666 0;
   0 0 0 0.03333;
   -2.28 0 -0.84 1;
   0.6 0 -4.8 -4.9];

B=[-0.0000916 0.0007416;
    0 0;
   -0.11 0;
   -8.7 0];

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

D=[0 0; 0 0]

% 3.29(a) - Discretization, Sampling time T=1sec
T=1

% Discrete-time system
[Ad,Bd]=c2d(A,B,T);
disp(' ')
disp('(b) - Discrete-time system')
Ad
Bd

% 3.29(b) - Response due to unit ramp input u1=t, u2=0
k=0:1:15;
u(:,1)=k';
u(:,2)=zeros(length(k),1);
dlsim(Ad,Bd,C,D,u)
grid
[xc,yc]=ginput(1)
text(xc,yc,'y1')
[xc,yc]=ginput(1)
text(xc,yc,'y2')
ylabel('outputs')
xlabel('no. of samples')

% 3.29(c) - Transfer function
[num,den]=ss2tf(Ad,Bd,C,D,1);
disp(' ')
disp('g11(z)=y1(z)/u1(z):')
printsys(num(1,:),den)
disp(' ')
disp('g21(z)=y2(z)/u1(z):')
printsys(num(2,:),den)

[num,den]=ss2tf(Ad,Bd,C,D,2);
disp(' ')
disp('g12(z)=y1(z)/u2(z):')
printsys(num(1,:),den)
disp(' ')
disp('g22(z)=y2(z)/u2(z):')
printsys(num(2,:),den)

% System poles
disp(' ')
disp('System poles:')
poles=roots(den)


