%% Decompose Uncertain Model Using lftdata
% You decompose an uncertain model into a fixed certain part and normalized uncertain part using the lftdata command. To see how this command works, create a 2-by-2 uncertain matrix (umat) using three uncertain real parameters.

delta = ureal('delta',2); 
eta = ureal('eta',6); 
rho = ureal('rho',-1); 
A = [3+delta+eta delta/eta;7+rho rho+delta*eta]

%
% The umat A depends on two occurrences of delta, three occurrences of eta, and one occurrence of rho.
% Decompose A into M and Delta.

[M,Delta] = lftdata(A);

%
% M is a numeric matrix.

M

%
% Delta is a umat with the same uncertainty dependence as A.

Delta

% To examine some of the characteristics of Delta, sample it at three points. Note that:
%
% The sampled value of Delta is always diagonal.
% The sampled values always range between -1 and 1, because Delta is normalized.
% The sampled matrices each contain three independent values. Duplication of the entries is consistent with the dependence of Delta and A on the three uncertain real parameters.

usample(Delta,3)

%
% Verify that the maximum gain of Delta is 1.

maxnorm = wcnorm(Delta)

%
% Finally, verify that lft(Delta,M) is the same as A. To do so, take the difference, and use the 'full' option in simplify to remove redundant dependencies on uncertain elements.

simplify(lft(Delta,M)-A,'full')

%
%% Advanced Syntax of lftdata
% Even for the advanced user, the variable Delta will actually not be that useful, as it is still a complex object. On the other hand, its internal structure is described completely using a 3rd (and 4th) output argument.

[M,Delta,BlkStruct,NormUnc] = lftdata(A); 

% The rows of BlkStruct correspond to the uncertain elements named in fieldnames(A.Uncertainty). The elements of BlkStruct describe the size, type and number-of-copies of the uncertain elements in A, and implicitly delineate the exact block-diagonal structure of Delta. Note that the range/bound information about each uncertain element is not included in BlkStruct.

BlkStruct(1)
BlkStruct(2) 
BlkStruct(3) 

% Together, these entries mean that Delta is a block diagonal augmentation of the normalized version of the three uncertain elements.
% The first element is named 'delta'. It is 1-by-1; it is of class ureal; and there are two copies diagonally augmented.
% The second element is named 'eta'. It is 1-by-1; it is of class ureal; and there are three copies diagonally augmented.
% The third element is named 'rho'. It is 1-by-1; it is of class ureal; and there is one copy,
% The fourth output argument of lftdata contains a cell array of normalized uncertain elements. The cell array contains as many occurrences of each element as there are occurrences in the original uncertain object A.

size(NormUnc) 
NormUnc{1} 
isequal(NormUnc{2},NormUnc{1}) 
NormUnc{3} 
isequal(NormUnc{4},NormUnc{3}) 
isequal(NormUnc{5},NormUnc{3}) 
NormUnc{6} 

% Each normalized element has 'Normalized' appended to its original name to avoid confusion. When normalized,
% ureal objects have nominal value of 0, and range from –1 to 1.
% ultidyn objects are norm bounded, with norm bound of 1.
% umargin objects are converted to norm-bounded ultidyn objects with norm bound of 1.
% ucomplex objects have nominal value of 0, and radius 1.
% ucomplexm objects have nominal value of 0, and identity matrices for each of the WL and WR weights.
% The possible behaviors of Delta and blkdiag(NormUnc{:}) are the same. Consequently, the possible behaviors of A and lft(blkdiag(NormUnc{:}),M) are the same.
% Hence, by manipulating M, BlkStruct and NormUnc, a you can have direct access to all of the linear fractional transformation details, and can work at the level of the theorems and algorithms that underlie the methods.
%
% Copyright 2012 The MathWorks, Inc.