%  Example 9.1.  Full information control gain generation.
clear
%  Define the plant model.
A=1;
Bu=1;
Bw=2;
Cy=[10
     0];
Dyu=[0
     1];
Dyw=[0
     0];
P=pck(A,[Bw Bu],Cy,[Dyw Dyu]);
%  Define the performance bound for the suboptimal control.
gam=20/sqrt(97);
%  Find the steady-state full information gain.
[k,g,gfin,ax,hamx]=hinffi(P,1,gam,gam,0.1);
k
%  Define the time vector for use in evaluating the gain.
tf=3;
t=0:.005:tf;
%  Generate the gain using the analytic formula derived from the 
%    Hamiltonian.
kot=25*(exp(2*(tf-t))-exp(2*(t-tf)))./(0.25*exp(2*(tf-t))+0.75*exp(2*(t-tf)));
%  Plot the gain.
set(0,'DefaultAxesFontName','times')
set(0,'DefaultAxesFontSize',16)
set(0,'DefaultTextFontName','times')
figure(1)
clf
plot(t,kot)
xlabel('Time (sec)')
ylabel('Feedback gain')
axis([0 tf -10 110])
grid
%  Generate the gain by solving the Riccati equation.
%    This provides a check on the analytic solution.
P=zeros(1,length(t));
for i=length(t):-1:2,
  P(i-1)=P(i)-0.005*(-A'*P(i)-P(i)*A-Cy'*Cy+P(i)*(Bu*Bu'-gam^(-2)*Bw*Bw')*P(i));
end
%  Plot the gain.
figure(2)
clf
plot(t,Bu'*P)
xlabel('Time (sec)')
ylabel('Feedback gain')
axis([0 tf -10 110])
grid
