%% Solve System of LMIs
% Consider the problem of finding P > I such that:
% A_1^TP + P{A_1} < 0,
% A_2^TP + P{A_2} < 0,
% A_3^TP + P{A_3} < 0,
% with data
%  A_1 = \left( {\matrix{
%   { - 1} & 2  \cr
%   1 & { - 3}  \cr
% } } \right),{\rm{ }}A_2 = \left( {\matrix{
%   { - 0.8} & {1.5}  \cr
%   {1.3} & { - 2.7}  \cr
% } } \right),{\rm{ }}A_3 = \left( {\matrix{
%   { - 1.4} & {0.9}  \cr
%   {0.7} & { - 2.0}  \cr
% } } \right ).
% This problem arises when studying the quadratic stability of the polytope of the matrices, {\rm{Co}}\left\{ {{A_1},{A_2},{A_3}} \right\}.
% To assess feasibility using feasp, first enter the LMIs.

setlmis([]) 
p = lmivar(1,[2 1]);

A1 = [-1 2;1 -3];
A2 = [-0.8 1.5; 1.3 -2.7];
A3 = [-1.4 0.9;0.7 -2.0];

lmiterm([1 1 1 p],1,A1,'s');     % LMI #1 
lmiterm([2 1 1 p],1,A2,'s');     % LMI #2 
lmiterm([3 1 1 p],1,A3,'s');     % LMI #3 
lmiterm([-4 1 1 p],1,1);         % LMI #4: P 
lmiterm([4 1 1 0],1);            % LMI #4: I 
lmis = getlmis;

%
% Call feasp to a find a feasible decision vector.

[tmin,xfeas] = feasp(lmis);

%
% The result tmin = -3.1363 means that the problem is feasible. Therefore, the dynamical system \dot x = A\left( t \right)x is quadratically stable for A\left( t \right) \in {\rm{Co}}\left\{ {{A_1},{A_2},{A_3}} \right\}.
% To obtain a Lyapunov matrix P proving the quadratic stability, use dec2mat.

P = dec2mat(lmis,xfeas,p)

%
% It is possible to add further constraints on this feasibility problem. For instance, the following command bounds the Frobenius norm of P by 10 while asking tmin to be less than or equal to –1.

options = [0,0,10,0,0];
[tmin,xfeas] = feasp(lmis,options,-1);

% The third entry of options sets the feasibility radius to 10 while the third argument to feasp, -1, sets the target value for tmin. This constraint yields tmin = -1.011 and a matrix P with largest eigenvalue {\lambda _{max}}\left( P \right) = 8.4653.
%

P = dec2mat(lmis,xfeas,p);
e = eig(P)

% Copyright 2012 The MathWorks, Inc.