%  Example 4.5.  System 2-norm computation
clear
%  Define the Plant.
A=[0 1
   0 0];
Bu=[0 1]';
Bw=[0 0
    1 0];
Cm=[1 0];
Cy=[1 0
    0 0];
Dmw=[0 1];
Dyu=[0 1]';
Dyw=zeros(2);
%  Define the Controller.
Ac=[-1.6    1
    -0.68 -0.4];
Bcm=[1.6 0.64]';
Cc=[-0.04 -0.4];
Dcm=0;
%  Generate the closed loop state model.
Acl=[A+Bu*Dcm*Cm Bu*Cc
       Bcm*Cm      Ac ];
Bcl=[Bw+Bu*Dcm*Dmw
        Bcm*Dmw   ];
Ccl=[Cy+Dyu*Dcm*Cm Dyu*Cc];
Dcl=Dyw+Dyu*Dcm*Dmw;
%  Compute the system 2-norm.
Lc=lyap(Acl,Bcl*Bcl');
J=sqrt(trace(Ccl*Lc*Ccl'))
%  Alternative computation of the system 2-norm.
Lo=lyap(Acl',Ccl'*Ccl);
J=sqrt(trace(Bcl'*Lo*Bcl))
%  A function for computing the system 2-norm is provided in the Matlab
%  mu-syn toolbox.
Gcl=pck(Acl,Bcl,Ccl,Dcl);
J=h2norm(Gcl)
