% Solution of Problem 2.10(b)

disp('Solution for figure (a)')
disp('-----------------------')
ng1=[3 0]; dg1=[1 1 0];
ng2=5; dg2=[1 0 2];

% First unit feedback
[ng3,dg3]=feedback(ng1,dg1,1,1,-1);

% Parallel connection of G3 and unit gain element
[ng4,dg4]=parallel(ng3,dg3,-1,1);

% Second unit feedback
[ng5,dg5]=feedback(ng2,dg2,1,1,-1);

% Serial connection of G4 and G5
[num,den]=series(ng4,dg4,ng5,dg5);
disp(' ')
disp('Transfer function for system (a) in Problem 2.10')
printsys(num,den,'s')
[num,den]=minreal(num,den,1.e-20);

printsys(num,den,'s')

disp(' ')
disp('Solution for figure (b)')
disp('-----------------------')

% u2=0
% G11(s)
disp(' ')
disp('1. G11(s):')
[ng11,dg11]=feedback(ng1,dg1,ng2,dg2,-1);
[ng11,dg11]=minreal(ng11,dg11,1.e-20);
printsys(ng11,dg11,'s')

% G12(s)
disp(' ')
disp('2. G12(s):')
[ng12,dg12]=series(ng1,dg1,ng2,dg2);
[ng12,dg12]=feedback(ng12,dg12,1,1,-1);
[ng12,dg12]=minreal(ng12,dg12,1.e-20);
printsys(ng12,dg12,'s')

% u1=0
% G21(s)
disp(' ')
disp('3. G21(s):')
[ng21,dg21]=series(ng2,dg2,ng1,dg1);
[ng21,dg21]=feedback(ng21,dg21,1,1,-1);
[ng21,dg21]=minreal(ng21,dg21,1.e-20);
printsys(ng21,dg21,'s')

%G22(s)
disp(' ')
disp('4. G22(s):')
[ng22,dg22]=feedback(ng2,dg2,ng1,dg1,-1);
[ng22,dg22]=minreal(ng22,dg22,1.e-20);
printsys(ng22,dg22,'s')
