% Solution of Problem 2.9
% Description of the system
ng1=1; dg1=[1 1];
ng2=1; dg2=[1 1];
ng3=1; dg3=[1 2];
ng4=1; dg4=[1 0];
ng5=2; dg5=[1 0];
nh1=4; dh1=1;
nh2=10; dh2=1;

disp('Solution of 2.9(c)')
disp('------------------')

% Serial connection of G3 and G4
[ng6,dg6]=series(ng3,dg3,ng4,dg4);

% Feedback connection of G6 and H1
[ng7,dg7]=feedback(ng6,dg6,nh1,dh1,-1);

% Serial connection of G2, G7, and G5
[ng8,dg8]=series(ng2,dg2,ng7,dg7);
[ng8,dg8]=series(ng8,dg8,ng5,dg5);

% Feedback connection of G8 and H2
[ng9,dg9]=feedback(ng8,dg8,nh2,dh2,-1);

% Serial connection of G1 and G9
[ng10,dg10]=series(ng1,dg1,ng9,dg9);

% Unit feedback
[n,d]=feedback(ng10,dg10,1,1,-1);
printsys(n,d,'s')

disp(' ')
disp('Press ENTER to get the unit step response')

pause
t=0:0.1:10;
step(n,d,t)
grid
xlabel('time [s]')
ylabel('y')