%  Example 4.1.  Generates the closed loop state model and transfer functions,
%    given numerical parameters.
clear
%  Give numerical values to the model parameters.
t1=2;t2=3;k1=5;k2=7;k3=11;k4=13;a=17;b=23;
%  Define the plant modeL.
Ap=[-t1  0  0
     k2 -t2 0
	 0   1  0];
Bu=[k1 0 0]';
Bw=[0    0   0
    0  k2*k3 0
	0    0   0];
Cm=[0 0 1];
Cy=[0 0 -1
    0 0  0];
Dmw=[0 0 1];
Dyu=[0 1]';
Dyw=[1 0 0
     0 0 0];
%  Define the controller model.
Ac=-b;
Bcr=k4*(a-b);
Bcm=-k4*(a-b);
Cc=1;
Dcr=k4;
Dcm=-k4;
%  Generate the closed loop state model.
Acl=[Ap+Bu*Dcm*Cm Bu*Cc
        Bcm*Cm      Ac ]
temp1=[Bu*Dcr zeros(3,2)];
temp2=[Bcr zeros(1,2)];
Bcl=[Bw+Bu*Dcm*Dmw+temp1
        Bcm*Dmw+temp2]
Ccl=[Cy+Dyu*Dcm*Cm Dyu*Cc]
Dcl=Dyw+Dyu*Dcm*Dmw+[Dyu*Dcr zeros(2)]
%  Generate the closed loop transfer fucntion.
[nu1,de]=ss2tf(Acl,Bcl,Ccl,Dcl,1)
[nu2,de]=ss2tf(Acl,Bcl,Ccl,Dcl,2)
[nu3,de]=ss2tf(Acl,Bcl,Ccl,Dcl,3)
