% Problem 6.12
disp('Problem 6.12')
disp(' ')
disp('State-space model:')

A=[ -0.194 0.0628 0 0 0
    1.306 -2.132 0.9807 0 0
    0 1.595 -3.149 1.547 0
    0 0.0355 2.632 -4.257 1.855
    0 0.00227 0 0.1636 -0.1625]

B=[0 0.0632 0.0838 0.1004 0.0063
   0 0 -0.1396 -0.206 -0.0128]'

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

D=[0 0
   0 0]

% Transfer functions
[num1,den1]=ss2tf(A,B,C,D,1);
[num2,den2]=ss2tf(A,B,C,D,2);
disp(' ')
disp('Transfer functions g11,g21')
for i=1:2,
    for j=1:6,
        if num1(i,j) < 1.e-10
           num1(i,j)=0;
        end
        if num2(i,j) < 1.e-10
           num2(i,j)=0;
        end
    end
end
printsys(num1,den1)
disp(' ')
disp('Transfer funcrions g12,g22')
printsys(num2,den2)

% Closed-loop transfer functions
disp(' ')
disp('Closed-loop No. 11:')
[n11,d1c]=cloop(num1(1,:),den1,-1);
printsys(n11,d1c)
disp(' ')
disp('Closed-loop No. 21:')
[n21,d1c]=cloop(num1(2,:),den1,-1);
printsys(n21,d1c)

disp(' ')
disp('Closed-loop No. 12:')
[n12,d2c]=cloop(num2(1,:),den2,-1);
printsys(n12,d2c)
disp(' ')
disp('Closed-loop No. 22:')
[n22,d2c]=cloop(num2(2,:),den2,-1);
printsys(n22,d2c)