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

  1. function [acp,bcp,ccp,dcp,acl,bcl,ccl,dcl] = h2lqg(Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10)
  2. % [SS_CP,SS_CL]=H2LQG(TSS_,ARETYPE) computes the H-2 optimal controller
  3. %    for an "augmented" plant P(s) with suitable loop-shaping weighting
  4. %    functions such that the H2-norm of the closed-loop transfer function
  5. %    Ty1u1(s) is minimized. 
  6. %
  7. %   Required Input data:
  8. %     Augmented plant P(s): TSS_ = MKSYS(A,B1,B2,C1,C2,D11,D12,D21,D22,'tss')
  9. %
  10. %   Optional Input:      
  11. %     Riccati solver:    aretype = 'eigen' or 'Schur' (default = 'eigen')
  12. %
  13. %   Output data: 
  14. %     Controller F(s):     SS_CP = MKSYS(acp,bcp,ccp,dcp)
  15. %     CLTF of Ty1u1(s):    SS_CL = MKSYS(acl,bcl,ccl,dcl)
  16. %
  17. %   Caveat:  Note that D11 matrix must be zero or the problem is ill-posed;
  18. %   if D11 is nonzero, H2LQG computes the controller as if it were.
  19.  
  20. % R. Y. Chiang & M. G. Safonov 2/10/88 (revised 11/11/90)
  21. % Copyright (c) 1988 by the MathWorks, Inc.
  22. % All Rights Reserved.
  23. % ----------------------------------------------------------------------
  24.  
  25. % COMMENT:  This function also supports the format
  26. %     [ACP,BCP,CCP,DCP,ACP,BCL,CCL,DCL]=...
  27. %           H2LQG(A,B1,B2,C1,C2,D11,D12,D21,D22,ARETYPE)
  28. % where ARETYPE is optional with default 'eigen'.  If no
  29. % output arguments are supplied the variables (ss_cp,ss_cl,acp,bcp,ccp,
  30. % dcp,acl,bcl,ccl,dcl) are automatically returned in the main workspace.
  31.  
  32. %
  33. % --------------------------------------------------
  34. %
  35.  
  36. %  Expand input arguments or, if none present, load them from main workspace
  37.  
  38. nag1 = nargin;
  39. nag2 = nargout;
  40.  
  41.    inargs='(A,B1,B2,C1,C2,D11,D12,D21,D22,aretype)';
  42.    eval(mkargs(inargs,nargin,'tss'))
  43.  
  44. %  Create SYSP and DIMP, just in case not already present
  45. sysp=[A B1 B2;C1 D11 D12;C2 D21 D22];
  46. [dimx,dimu1]=size(B1);
  47. [dimy1,dimu2]=size(D12);
  48. [dimy2,dimu2]=size(D22);
  49. dimp=[dimx dimu1 dimu2 dimy1 dimy2];
  50.  
  51. % If aretype is not present, default to ARETYPE='eigen'
  52. if isnan(aretype) |min(size(aretype))==0
  53.   aretype='eigen';
  54. end
  55.  
  56. %
  57. % ---- Normalization :
  58. %
  59. ml = (D12'*D12)^(0.5);
  60. s1 = inv(ml);
  61. mr = (D21*D21')^(0.5);
  62. s2 = inv(mr);
  63. %
  64. b2 = B2*s1;
  65. c2 = s2*C2;
  66. d12 = D12*s1;
  67. d21 = s2*D21;
  68. d22 = s2*D22*s1;
  69. %
  70. %c1tl = (eye(dimy1)-d12*d12')*C1;            
  71. %b1tl = B1*(eye(dimu1)-d21'*d21);
  72. %
  73. % ---- Kc Riccati:
  74. %
  75. ax = A;
  76. bx = b2;
  77. [rb2,cb2] = size(b2);
  78. [rc1,cc1] = size(C1);
  79. [rc2,cc2] = size(c2);
  80. qx = C1'*C1;
  81. rx = eye(cb2);
  82. nx = C1'*d12;
  83.  
  84. qrnx = [qx nx;nx' rx];
  85. [kkx,x2,xerr] = lqrc(ax,bx,qrnx,aretype);
  86. %
  87. % ---- Kf Riccati:
  88. %
  89. ay = A';
  90. by = c2';
  91. qy = B1*B1';
  92. ry = eye(rc2);
  93. ny = B1*d21';
  94.  
  95. qrny = [qy ny;ny' ry];
  96. [kky,y2,yerr] = lqrc(ay,by,qrny,aretype);
  97. %
  98. kc = kkx;                % also equals to (b2'*x2+d12'*C1);
  99. kf = kky';               % also equals to (y2*c2'+B1*d21');
  100. %
  101. % ---- Compensator :
  102. %
  103. acp = A - kf*c2 - b2*kc + kf*d22*kc;
  104. bcp = kf;
  105. ccp = kc;
  106. [mb,cb] = size(bcp);
  107. [mc,cc] = size(ccp);
  108. %
  109. bcp = bcp*s2;
  110. ccp = -s1*ccp;
  111. dcp = -zeros(mc,cb);
  112. syscp = [acp,bcp;ccp dcp]; xcp = size(acp)*[1;0];
  113. %
  114. % ------------------------------------ Closed-loop TF (Ty1u1):
  115. %
  116. wacp = acp;
  117. wbcp = bcp*inv(s2);
  118. wccp = inv(s1)*ccp;
  119. wdcp = inv(s1)*dcp*inv(s2);
  120. sysp = [A B1 b2;C1 D11 d12;c2 d21 d22];
  121. dimp = [size(A)*[1 0]',...
  122.        size(B1)*[0 1]',size(b2)*[0 1]',...
  123.        size(C1)*[1 0]',size(c2)*[1 0]'];
  124. [acl,bcl,ccl,dcl] = lftf(sysp,dimp,wacp,wbcp,wccp,wdcp);
  125. syscl = [acl bcl;ccl dcl]; xcl = size(acl)*[1;0];
  126. %
  127. % If appropriate convert F(s) and Ty1u1(s) data to format similar
  128. % to the input to H2LQG:
  129. if nag2 == 0
  130.    % Case when used as script file with no output arguments
  131.    ss_cl=mksys(acl,bcl,ccl,dcl);
  132.    ss_cp=mksys(acp,bcp,ccp,dcp);
  133.    save hinf2 acp bcp ccp dcp acl bcl ccl dcl ss_cl ss_cp
  134.    hinfload
  135.    acp= 'Controller: (acp,bcp,ccp,dcp); Cost: (acl,bcl,ccl,dcl)';
  136. elseif xsflag
  137.    % Case     [SS_CP,SS_CL]=H2LQG(TSS_P,ARETYPE)
  138.    acp=mksys(acp,bcp,ccp,dcp);
  139.    if nag2>1,
  140.          bcp=mksys(acl,bcl,ccl,dcl);
  141.    end
  142. end
  143. % If none of the above, then ..
  144. %     [ACP,BCP,CCP,DCP,ACP,BCL,CCL,DCL]=...
  145. %                  H2LQG(A,B1,B2,C1,C2,D11,D12,D21,D22,ARETYPE)
  146.  
  147. % ------------ End of H2LQG.M 11/11/90 RYC/MGS
  148.  
  149.