home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 7.ddi / ROBUST.DI$ / LFTF.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  6.6 KB  |  209 lines

  1. function [aa,bb1,bb2,cc1,cc2,dd11,dd12,dd21,dd22] = lftf(Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10,Z11,Z12,Z13,Z14,Z15,Z16,Z17,Z18);
  2. % [TSS_] = LFTF(TSS_1,TSS_2); or [A,B1,B2,..] = LFTF(A11,B11,..,A21,B21,..); 
  3. % [SS_L] = LFTF(TSS_1,SS_2); or [AL,BL,CL,DL] = LFTF(A11,B11,..,AW,BW,CW,DW);
  4. % [SS_L] = LFTF(SS_1,TSS_2);
  5. %  Produces a linear fractional transform from [U1;U2] to [Y1;Y2]:
  6. %                                P1(s)
  7. %  optional              ---------------------                optional
  8. %  U1 (nu1) -----------> | P11(s)     P12(s) | -------------> Y1 (ny1)
  9. %               -------> | P21(s)     P22(s) | ------- 
  10. %               |        ---------------------       |          
  11. %               |      (nx  no. of states of P s))   |
  12. %               |        ---------------------       |        
  13. %  optional     -------- | P11(s)     P12(s) |<-------        optional
  14. %  Y2 (ny2) <----------- | P21(s)     P22(s) |<---------------U2 (nu2) 
  15. %                        ---------------------  
  16. %                                P2(s)
  17.  
  18.  
  19. % R. Y. Chiang & M. G. Safonov 7/1/87, 8/12/91
  20. % Copyright (c) 1988 by the MathWorks, Inc.
  21. % All Rights Reserved.
  22. % ---------------------------------------------------------------------
  23. %
  24. nag1 = nargin;
  25.  
  26. % First extract a,b1,b2,...,d22; at,bt1,bt2,...,dt22 from Z1,Z2,etc. 
  27.  
  28. % If P1(s) or P2(s) is SS_ format, convert to TSS_ format by padding
  29. % with empty matrices before extracting data and setting flags
  30. ssflag2=0;
  31. if issystem(Z2)
  32.    if nag1>2,
  33.        error('Only two input arguments allowed when any is a system')
  34.    end
  35.    if issame(branch(Z2,'ty'),'ss')
  36.      ssflag2=1;
  37.      [a,b,c,d]=branch(Z2);
  38.      Z2=mksys(a,b,[],c,[],d,[],[],[],'tss');
  39.    end
  40. end
  41.  
  42. ssflag1=0;
  43. if issystem(Z1)
  44.    if nag1>2,
  45.        error('Only two input arguments allowed when any is a system')
  46.    end
  47.    if issame(branch(Z1,'ty'),'ss')
  48.      ssflag1=1;
  49.      [a,b,c,d]=branch(Z1);
  50.      Z1=mksys(a,[],b,[],c,[],[],[],d,'tss');
  51.    end
  52.    % if Z1 is a system, expand input arguments
  53.    inargs=...
  54.    '(a,b1,b2,c1,c2,d11,d12,d21,d22,at,bt1,bt2,ct1,ct2,dt11,dt12,dt21,dt22)';
  55.    eval(mkargs(inargs,nag1,'tss,tss'))
  56. else
  57.    xsflag=0;
  58.    if nag1 == 13 | nag1==18
  59.       a=Z1; b1=Z2; b2=Z3; c1=Z4; c2=Z5; d11=Z6; d12=Z7; d21=Z8; d22=Z9;
  60.       if nag1==13; % input lftf(a,b1,b2,...,d22,at,bt2,ct1,dt11)
  61.          ssflag2=1;
  62.          at =Z10; bt1 =Z11; bt2 =[];
  63.          ct1=Z12; dt11=Z13; dt12=[];
  64.          ct2=[];  dt21=[];  dt22=[];
  65.       else  % input lftf(a,b1,b2,...,d22,at,bt1,...,dt22)
  66.          ssflag2=0;
  67.          at=Z10;  bt1 =Z11; bt2 =Z12; ct1 =Z13; ct2=Z14;
  68.          dt11=Z15; dt12=Z16; dt21=Z17; dt22=Z18;
  69.       end
  70.    elseif nag1 == 6 |nag1==4
  71.       [a,b1,b2,c1,c2,d11,d12,d21,d22] = asys2ss(Z1,Z2);
  72.       if nag1==6  % input lftf(sysp,dimp,at,bt1,ct1,ct2)
  73.          ssflag2=1;
  74.          at = Z3;  bt1 =Z4; bt2= [];
  75.          ct1 = Z5; dt11=Z6; dt12=[];
  76.          ct2=[];   dt21=[]; dt22=[];
  77.       else       % input lftf(sysp1,dimp1,sysp1,dimp2)
  78.           ssflag2=0;
  79.           [at,bt1,bt2,ct1,ct2,dt11,dt12,dt21,dt22] = asys2ss(Z3,Z4);
  80.       end
  81.    else
  82.       error('Incorrect number of input arguments')
  83.    end
  84. end
  85.  
  86. %  We now have the two state-spaces a,b1,b2,c1,c2,d11,d12,d21,d22 and
  87. %  at,bt1,bt2,ct2,ct2,dt11,dt12,d21,dt22 and three true/false flags:
  88. %      ssflag1  (true if P1(s) had no U1,Y1 present)
  89. %      ssflag2  (true if P2(s) had no U2,Y2 present)
  90. %      xsflag   (true input arguments were in system format)
  91.  
  92.  
  93. % ------------------------------------------------------------------
  94. % Next get the dimensions of states, inputs and outputs
  95. % and check compatibility
  96.  
  97. n = size(a)*[1;0];
  98. p1y1=size([c1 d11 d12])*[1;0];
  99. p1y2=size([c2 d21 d22])*[1;0];
  100. p1u1=size([b1; d11; d21])*[0;1];
  101. p1u2=size([b2; d12; d22])*[0;1];
  102. dimp=[n p1u1 p1u2 p1y1 p1y2];
  103.  
  104. nt = size(at)*[1;0];
  105. p2y1=size([ct1 dt11 dt12])*[1;0];
  106. p2y2=size([ct2 dt21 dt22])*[1;0];
  107. p2u1=size([bt1; dt11; dt21])*[0;1];
  108. p2u2=size([bt2; dt12; dt22])*[0;1];
  109. dimpt=[nt p2u1 p2u2 p2y1 p2y2];
  110.  
  111. %
  112. if p1u2 ~= p2y1
  113.     error('SYSP1 input U2 must be same dimension as SYSP2 output Y1');
  114. end
  115. if p2u1 ~= p1y2
  116.     error('SYSP2 input U1 must be same dimension as SYSP1 output Y2')
  117. end
  118. %
  119.  
  120.  
  121. % Add fictitious nonminimal states if needed
  122. % in order to overcome the matlab empty-matrix bug
  123. if nt == 0
  124.     at=-1;
  125.     bt1=zeros(1,p2u1);
  126.     bt2=zeros(1,p2u2);
  127.     ct1=zeros(p2y1,1);
  128.     ct2=zeros(p2y2,1);
  129. end
  130.  
  131. if n == 0
  132.    a=-1;
  133.    b1=zeros(1,p1u1);
  134.    b2=zeros(1,p1u2);
  135.    c1=zeros(p1y1,1);
  136.    c2=zeros(p1y2,1);
  137. end
  138.  
  139. %  Now we compute the state-space aa,bb1,bb2,cc1,cc2,dd11,dd12,dd21,dd22
  140. %  of the two-port lftf
  141.  
  142. id = inv(eye(size(d22*dt11)*[1 0]') - d22*dt11);
  143. idt = inv(eye(size(dt11*d22)*[1 0]') - dt11*d22);
  144.  
  145. dd11 = d11+d12*dt11*id*d21;
  146. dd22 = dt22+dt21*d22*idt*dt12;
  147. dd12 = d12*idt*dt12;
  148. dd21 = dt21*id*d21;
  149.  
  150. % now compute the lftf aa,bb1,bb2,cc1, and cc2 matrices
  151.  
  152. aa  = [a+b2*dt11*id*c2      b2*idt*ct1;
  153.        bt1*id*c2            at+bt1*id*d22*ct1     ];
  154. bb1 = [b1+b2*dt11*id*d21;
  155.        bt1*id*d21       ];
  156. bb2 = [b2*idt*dt12;
  157.        bt2+bt1*d22*idt*dt12 ];
  158. cc1 = [c1+d12*dt11*id*c2    d12*idt*ct1           ];
  159. cc2 = [dt21*id*c2           ct2+dt21*d22*idt*ct1  ];
  160.  
  161. % Now remove the fictitious states, if  needed
  162.  
  163. if nt == 0
  164.    s=1:n;
  165.    aa=aa(s,s);
  166.    if min(size(bb1))>0, bb1=bb1(s,:);end
  167.    if min(size(bb2))>0, bb2=bb2(s,:);end
  168.    if min(size(cc1))>0, cc1=cc1(:,s);end
  169.    if min(size(cc2))>0, cc2=cc2(:,s);end
  170. end
  171. if n == 0
  172.    t=(2:nt+1);
  173.    aa=aa(t,t);
  174.    if min(size(bb1))>0, bb1=bb1(t,:);end
  175.    if min(size(bb2))>0, bb2=bb2(t,:);end
  176.    if min(size(cc1))>0, cc1=cc1(:,t);end
  177.    if min(size(cc2))>0, cc2=cc2(:,t);end
  178. end
  179.  
  180. %  Done with computing aa,bb1,bb2, etc.
  181.  
  182. %----------------------------------------------------------------
  183. %  Now reformat output if needed:
  184. %
  185. if xsflag
  186.    if ssflag1                           % output [ss_l]
  187.      aa=mksys(aa,bb2,cc2,dd22);
  188.    elseif ssflag2 % output [ss_l]
  189.      aa=mksys(aa,bb1,cc1,dd11);
  190.    elseif ~ssflag1 & ~ssflag2           % output [tss_]
  191.      aa = mksys(aa,bb1,bb2,cc1,cc2,dd11,dd12,dd21,dd22,'tss');
  192.    end
  193.    bb1=[];bb2=[];cc1=[];cc2=[];dd11=[];dd12=[];dd21=[];dd22=[];
  194. else
  195.    if nag1 == 4                         % output [sysp,dimp]
  196.       sysp=[aa,bb1,bb2;cc1,dd11,dd12;cc2,dd21,dd22];
  197.       dimp = [n+nt,p1u1,p2u2,p1y1,p2u2];
  198.       aa = sysp;
  199.       bb1 = dimp;
  200.       bb2=[];cc1=[];cc2=[];dd11=[];dd12=[];dd21=[];dd22=[];
  201.    elseif nag1==13 | nag1==6            %  output a[l,bl,cl,dl]
  202.       bb2=cc1;
  203.       cc1=dd11;
  204.       cc2=[];dd11=[];dd12=[];dd21=[];dd22=[];      
  205.    end
  206. end   
  207. %
  208. % --------- End of LFTF.M --- RYC/MGS 7/1/87, 8/12/91 %
  209.