%
% Lecture 7, Global quadratic Lyapunov function 
% Example from Slide 9
% M. Oishi, Feb 4, 2008.
% EECE 571M/491M 
%

% define the constants
A1 = [-1 1; -1 -1]; 
A2 = [-2 1; -1 -2];

% the below is from lmiedit, written with A1 and A2 variables unknown; use 
% 'write' to put the transformed commands into a file and then use a 
% text editor to modify that file (e.g., add A1 and A2, post-processing, etc.) 

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

  lmiterm([1 1 1 P],A1',1,'s');                   % LMI #1: A1'*P+P*A1

  lmiterm([2 1 1 P],A2',1,'s');                   % LMI #2: A2'*P+P*A2

  lmiterm([-3 1 1 P],1,1);                          % LMI #3: P         

  lmisys=getlmis;                                                     

% solve the LMI.  Answer is good if tmin <= 0.
[tmin,pfeas]=feasp(lmisys);		

% now extract matrix variables from result of LMI solver (pfeas)
% be sure to use the same identifier the variable was encoded with in lmiedit 
Pfinal = dec2mat(lmisys,pfeas,P);


%
% NOTE: For other types of variables, use 'help lmivar' to 
% properly encode block diagonals, unstructured matrices, etc.
%
% One brute-force way to make a matrix have non-negative elements is to define 
% each element of the matrix as a 1x1 matrix variable > 0.
% 

