% Hinf control design
WS = ss(1);
% WS = ss(10/(s+10)); % weight for sensitivity function)

systemnames = 'P WS';
inputvar = '[ r; u ]';
outputvar = '[ WS; r-P ]';
input_to_P = '[ u ]';
input_to_WS = '[ r-P ]';
cleanupsysic = 'yes';
G = sysic;

[K_hinf, clp, gopt] = hinfsyn(G, 1, 1, 'DISPLAY', 'on');

figure(1);
bode(K_hinf, 'r--');

figure(2);
nyquist(P*K_hinf, 'r--'); % check for closed-loop stability

S_hinf = 1/(1+P*K_hinf); % sensitivity function

figure(3);
bodemag(S_hinf, 'r--', gopt*inv(WS), 'g--');

figure(4);
T_hinf = 1 - S_hinf; % complementary sensitivity function
step(T_hinf, 'r--', 10); % step response
