clear all;
close all;

s = tf('s');

P0 = 1/((s - 1)*(s + 1)); % nominal plant
WT = 0.4*s/(s + 1); % weighting for complementary sensitivity function
WS = 0.1/(s+0.1); % weighting for sensitivity function
gam = 1; % to be minimized

WSgam = ss(WS/gam); % at least one sub-system is given in SSR to get G in SSR

systemnames = 'P0 WT WSgam';
inputvar = '[ w; u ]';
outputvar = '[ WT; WSgam; -w-P0 ]';
input_to_P0 = '[ u ]';
input_to_WT = '[ P0 ]';
input_to_WSgam = '[ P0 + w ]';
cleanupsysic = 'yes';
G = sysic;

[K, clp, gopt] = hinfsyn(G, 1, 1, 'GMIN', 1., 'GMAX', 1, 'DISPLAY', 'on');

figure(1);
S = 1/(1 + P0 * K); % gain plot of sensitivity function
bodemag(S, 'b', 1/WSgam, 'g');
legend('S', 'gamma/WS');

figure(2);
T = 1 - S; % gain plot of complementary sensitivity function
bodemag(T, 'b', 1/WT, 'g');
legend('T', '1/WT');
