%  Example 9.2.  H-infinity full information control of a DC motor.
clear
%  Define the plant model.
A=[0  1
   0 -1];
Bu=[ 0
    10];
Bw=[0
    2];
Cy=[10 0
     0 0];
Dyu=[0
     1];
Dyw=[0
     0];
Plant=pck(A,[Bw Bu],Cy,[Dyw Dyu]);
%  Generate the full information control gain with gamma = 1.
K=hinffi(Plant,1,1,1,0.01);
K=-K(1:2)
%  Generate the closed loop model.
Acl=A-Bu*K;
Bcl=[0;1];
Cclew=[1 0];
Ccluw=-10*K;
%  Generate the poles of the closed loop system.
poles=eig(Acl)
%  Generate the frequency response from w to e.
w=logspace(0,2);
mage=bode(Acl,Bcl,Cclew,0,1,w);
%  Generate the frequency response from w to u.
magu=bode(Acl,Bcl,Ccluw,0,1,w);
%  Generate a full information controller with gamma = 0.21
K021=hinffi(Plant,1,0.21,0.21,0.01);
K021=-K021(1:2)
%  Generate closed loop model.
Acl021=A-Bu*K021;
Ccluw021=-10*K021;
%  Generate the poles of the closed loop system.
poles021=eig(Acl021)
%  Generate the frequency response from w to e.
mage021=bode(Acl021,Bcl,Cclew,0,1,w);
%  Generate the frequency response from w to u.
magu021=bode(Acl021,Bcl,Ccluw021,0,1,w);
%  Plot the frequency response from w to e.
set(0,'DefaultAxesFontName','times')
set(0,'DefaultAxesFontSize',16)
set(0,'DefaultTextFontName','times')
figure(1)
clf
plot(w,20*log10(mage),'r-',w,20*log10(mage021),'r--')
xlabel('Frequency (rad/sec)')
ylabel('Gain (dB)')
grid
legend('{\it{\gamma}} = 1','{\it{\gamma}} = 0.2')
set(gca,'xscale','log')
%  Plot the frequency response from w to u.
figure(2)
clf
plot(w,20*log10(magu),'r-',w,20*log10(magu021),'r--')
xlabel('Frequency (rad/sec)')
ylabel('Gain (dB)')
grid
legend('{\it{\gamma}} = 1','{\it{\gamma}} = 0.2')
set(gca,'xscale','log')
