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

A=[ 0 0.55 0 0 0 -5.5 0 0 0
    0  0 1 0 0  0 0 0 0
    0 -3.3 -0.05 6 0 3.3 0 0 0
    0 0 0 -3.3 3.3 0 0 0 0
    0 0 -5.2 0 -13 0 0 0 0
    0 0 0 0 0 0 1 0 0
    0 3.3 0 0 0 -3.3 -0.05 6 0
    0 0 0 0 0 0 0 -3.3 3.3
    0 0 0 0 0 0 -5.2 0 -13]

B=[0 0 0 0 13 0 0 0 0
   0 0 0 0 0 0 0 0 13]'

C=[1 0.43 0 0 0 0 0 0 0
   0 0 0 1 0 0 0 0 0
   -1 0 0 0 0 0.43 0 0 0
   0 0 0 0 0 0 0 1 0]

D=[0 0
   0 0
   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,g31,g41')
for i=1:length(den1),
    if den1(i) < 1.e-10
       den1(i)=0;
    end
    for j=1:4,
        if num1(j,i) < 1.e-10
           num1(j,i)=0;
        end
    end
end
printsys(num1,den1)
disp(' ')
disp('Transfer functions g12,g22,g32,g42')
for i=1:length(den2),
    if den2(i) < 1.e-10
       den2(i)=0;
    end
    for j=1:4,
        if num2(j,i) < 1.e-10
           num2(j,i)=0;
        end
    end
end
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. 31:')
[n31,d1c]=cloop(num1(3,:),den1,-1);
printsys(n31,d1c)
disp(' ')
disp('Closed-loop No. 41:')
[n41,d1c]=cloop(num1(4,:),den1,-1);
printsys(n41,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)
disp(' ')
disp('Closed-loop No. 32:')
[n32,d2c]=cloop(num2(3,:),den2,-1);
printsys(n32,d2c)
disp(' ')
disp('Closed-loop No. 42:')
[n42,d2c]=cloop(num2(4,:),den2,-1);
printsys(n42,d2c)
