%  Example 10.1.  Hinf controller design and simulation.
clear
%  Define the wind torque bound.
Wb=70;
%  Define the output weighting.
Wq=13;
%  Define the plant model (with normalized inputs).
A=[0   1
   0 -0.1];
Bu=[0 0.001]';
Bw=[    0    0
    0.001*Wb 0];
Cy=[Wq 0
    0  0];
Cm=[1 0];
Dyw=zeros(2);
Dyu=[0 1]';
Dmw=[0 1];
Dmu=0;
Plant=pck(A,[Bw Bu],[Cy;Cm],[Dyw Dyu;Dmw Dmu]);
%  Define the performance bound.
gamma=90;
gm2=1/gamma/gamma;
%  Generate the steady-state H-infinity suboptimal controller.
[Kss,Gcl]=hinfsyn(Plant,1,1,gamma,gamma,0.1);
%  Define the time vector for simulation.
t=0:0.1:100;
%  Define the inputs for simulating the closed loop system.
infun='[1; randn(1)]';
wv=siggen(infun,t);
%  Simulate the closed loop system.
y=trsp(Gcl,wv);
%  Generate the unweighted output.
yscaled=mmult([1/Wq 0;0 1],y);
%  Plot the simulation results.
set(0,'DefaultAxesFontName','times')
set(0,'DefaultAxesFontSize',16)
set(0,'DefaultTextFontName','times')
figure(1)
clf
subplot(211),vplot(sel(yscaled,1,1),'r-')
grid
xlabel('Time (sec)')
ylabel('Angle error (deg)')
subplot(212),vplot(sel(y,2,1),'r-')
grid
xlabel('Time (sec)')
ylabel('Control torque (N-m)')
