%% Specify LMI System
% Consider a stable transfer function,
% G\left( s \right) = C{\left( {sI - A} \right)^{ - 1}}B.
% Suppose that G has four inputs, four outputs, and six states. Consider also a set of input/output scaling matrices D with block-diagonal structure given by:
% D = \left( {\matrix{
%   {{d_1}} & 0 & 0 & 0  \cr
%   0 & {{d_1}} & 0 & 0  \cr
%   0 & 0 & {{d_2}} & {{d_3}}  \cr
%   0 & 0 & {{d_4}} & {{d_5}}  \cr
% } } \right).
% The following problem arises in the robust stability analysis of systems with time-varying uncertainty [4]. Find, if any, a scaling D with the specified structure, such that the largest gain across frequency of DG(s)D^{-1} is less than 1.
% This problem has a simple LMI formulation: There exists an adequate scaling D if the following feasibility problem has solutions. Find two symmetric matrices X \in {R_{6 \times 6}} and S = {D^T}D \in {R_{4 \times 4}} such that:
% \left( {\matrix{
%    {{A^T}X + XA + {C^T}SC} & {XB}  \cr
%    {{B^T}X} & { - S}  \cr
%  } } \right) < 0,
% X > 0,
% S > 1.
% You can use the LMI Editor to specify the LMI problem described by these expressions, as shown in Specify LMIs with the LMI Editor GUI. Alternatively, define it at the command line using lmivar and lmiterm, as follows.
% For this example, use the following values for A, B, and C.

A = [  -0.8715    0.5202    0.7474    1.0778   -0.9686    0.1005;
       -0.5577   -1.0843    1.8912    0.2523    1.0641   -0.0345;
       -0.2615   -1.7539   -1.5452   -0.2143    0.0923   -2.4192;
        0.6087   -1.0741    0.1306   -2.5575    2.3213    0.2388;
       -0.7169    0.3582   -1.4195    1.7043   -2.6530   -1.4276;
       -1.2944   -0.6752    1.6983    1.6764   -0.3646   -1.7730 ];
  
B = [       0    0.8998   -0.2130    0.9835;
            0   -0.3001         0   -0.2977;
      -1.0322         0   -1.0431    1.1437;
            0   -0.3451   -0.2701   -0.5316;
      -0.4189    1.0128   -0.4381         0;
            0         0   -0.4087         0];
 
C = [      0    2.0034         0    1.0289    0.1554    0.7135;
      0.9707    0.9510    0.7059    1.4580   -1.2371    0.3174;
           0         0    1.4158    0.0475   -2.1935    0.4136;
     -0.4383    0.6489   -1.6045    1.7463   -0.3334   -0.5771];

%
% Define the LMI variables X and S, and then specify the terms of each LMI.

setlmis([]) 
X = lmivar(1,[6 1]); 
S = lmivar(1,[2 0;2 1]);

% 1st LMI 
lmiterm([1 1 1 X],1,A,'s');
lmiterm([1 1 1 S],C',C); 
lmiterm([1 1 2 X],1,B); 
lmiterm([1 2 2 S],-1,1);

% 2nd LMI 
lmiterm([-2 1 1 X],1,1);

% 3rd LMI
lmiterm([-3 1 1 S],1,1); 
lmiterm([3 1 1 0],1);

LMISYS = getlmis;

% The lmivar commands define the two matrix variables, X and S. The lmiterm commands describe the terms in each LMI. getlmis returns the internal representation LMISYS of this LMI problem.
% For more details on how to use these commands, see:
% Initializing the LMI System
% Specifying the LMI Variables
% Specifying Individual LMIs
% For more information about how lmivar updates the internal representation of the LMI problem, see How lmivar and lmiterm Manage LMI Representation.
% Copyright 2012 The MathWorks, Inc.