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

  1. function [acp,bcp,ccp,dcp,acl,bcl,ccl,dcl] = dh2lqg(Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10)
  2. % [SS_CP,SS_CL] = DH2LQG(TSS_,ARETYPE) computes the discrete H2 controller
  3. %    for an "augmented" plant P(z) 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(z): 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(z):     SS_CP = MKSYS(acp,bcp,ccp,dcp)
  15. %     CLTF of Ty1u1(z):    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, DH2LQG 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. %          DH2LQG(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. nag1 = nargin;
  38. nag2 = nargout;
  39.  
  40. inargs='(A,B1,B2,C1,C2,D11,D12,D21,D22,aretype)';
  41. eval(mkargs(inargs,nargin,'tss'))
  42.  
  43. %  Create SYSP and DIMP, just in case not already present
  44. sysp=[A B1 B2;C1 D11 D12;C2 D21 D22];
  45. [dimx,dimu1]=size(B1);
  46. [dimy1,dimu2]=size(D12);
  47. [dimy2,dimu2]=size(D22);
  48. dimp=[dimx dimu1 dimu2 dimy1 dimy2];
  49.  
  50. % If aretype is not present, default to ARETYPE='eigen'
  51. if issame(aretype,NaN) |min(size(aretype))==0
  52.   aretype='eigen';
  53. end
  54.  
  55. %
  56. % ---- Normalization :
  57. %
  58. ml = (D12'*D12)^(0.5);
  59. s1 = inv(ml);
  60. mr = (D21*D21')^(0.5);
  61. s2 = inv(mr);
  62. %
  63. b2 = B2*s1;
  64. c2 = s2*C2;
  65. d12 = D12*s1;
  66. d21 = s2*D21;
  67. d22 = s2*D22*s1;
  68. %
  69. %c1tl = (eye(dimy1)-d12*d12')*C1;            
  70. %b1tl = B1*(eye(dimu1)-d21'*d21);
  71. %
  72. % ---- Kc Riccati:
  73. %
  74. ax = A;
  75. bx = b2;
  76. [rb2,cb2] = size(b2);
  77. [rc1,cc1] = size(C1);
  78. [rc2,cc2] = size(c2);
  79. qx = C1'*C1;
  80. rx = eye(cb2);
  81. nx = C1'*d12;
  82.  
  83. qrnx = [qx nx;nx' rx];
  84. [kkx,x2,xerr] = dlqrc(ax,bx,qrnx,aretype);
  85. %
  86. % ---- Kf Riccati:
  87. %
  88. ay = A';
  89. by = c2';
  90. qy = B1*B1';
  91. ry = eye(rc2);
  92. ny = B1*d21';
  93.  
  94. qrny = [qy ny;ny' ry];
  95. [kky,y2,yerr] = dlqrc(ay,by,qrny,aretype);
  96. %
  97. kc = kkx;                % also equals to (b2'*x2+d12'*C1);
  98. kf = kky';               % also equals to (y2*c2'+B1*d21');
  99. %
  100. % ---- Compensator :
  101. %
  102. acp = A - kf*c2 - b2*kc + kf*d22*kc;
  103. bcp = kf;
  104. ccp = kc;
  105. [mb,cb] = size(bcp);
  106. [mc,cc] = size(ccp);
  107. %
  108. bcp = bcp*s2;
  109. ccp = -s1*ccp;
  110. dcp = -zeros(mc,cb);
  111. syscp = [acp,bcp;ccp dcp]; xcp = size(acp)*[1;0];
  112. %
  113. % ------------------------------------ Closed-loop TF (Ty1u1):
  114. %
  115. wacp = acp;
  116. wbcp = bcp*inv(s2);
  117. wccp = inv(s1)*ccp;
  118. wdcp = inv(s1)*dcp*inv(s2);
  119. sysp = [A B1 b2;C1 D11 d12;c2 d21 d22];
  120. dimp = [size(A)*[1 0]',...
  121.        size(B1)*[0 1]',size(b2)*[0 1]',...
  122.        size(C1)*[1 0]',size(c2)*[1 0]'];
  123. [acl,bcl,ccl,dcl] = lftf(sysp,dimp,wacp,wbcp,wccp,wdcp);
  124. syscl = [acl bcl;ccl dcl]; xcl = size(acl)*[1;0];
  125. %
  126. % If appropriate convert F(z) and Ty1u1(z) data to format similar
  127. % to the input to DH2LQG:
  128. if xsflag
  129.    % Case     [SS_CP,SS_CL] = DH2LQG(TSS_P,ARETYPE)
  130.    acp=mksys(acp,bcp,ccp,dcp);
  131.    if nag2>1,
  132.          bcp=mksys(acl,bcl,ccl,dcl);
  133.    end
  134. end
  135. % If none of the above, then ..
  136. %     [ACP,BCP,CCP,DCP,ACP,BCL,CCL,DCL]=...
  137. %                 DH2LQG(A,B1,B2,C1,C2,D11,D12,D21,D22,ARETYPE)
  138. %
  139. % ------------ End of DH2LQG.M 11/11/90 RYC/MGS
  140.  
  141.