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

  1. function [ahed,bhed,ched,dhed,aug,hsv,slbig,srbig] = schbal(Z1,Z2,Z3,Z4,Z5,Z6)
  2. % [SS_H,AUG,HSV,SLBIG,SRBIG] = SCHBAL(SS_,TYPE,NO) or
  3. % [AHED,BHED,CHED,DHED,AUG,HSV,SLBIG,SRBIG]=SCHBAL(A,B,C,D,TYPE,NO) performs  
  4. %    Schur method model reduction on G(s):=(a,b,c,d) such that the infinity-
  5. %    norm of the error (Ghed(s) - G(s)) <= sum of the 2(n-k) smaller Hankel
  6. %    singular values.
  7. %
  8. %         (ahed,bhed,ched,dhed) = (slbig'*a*srbig,slbig'*b,c*srbig,d)
  9. %   Based on the "TYPE" selected, you have the following options:
  10. %
  11. %    1). TYPE = 1  --- no: size "k" of the reduced order model.
  12. %
  13. %    2). TYPE = 2  --- find k-th order model such that the total error
  14. %                      is less than "no".
  15. %
  16. %    3). TYPE = 3  --- disply all the Hankel SV prompt for "k" (in this
  17. %                      case, no need to specify "no").
  18. %
  19. %    AUG = [No. of state(s) removed, Error bound], HSV = Hankel SV's.
  20.  
  21. % R. Y. Chiang & M. G. Safonov 9/11/87
  22. % Copyright (c) 1988 by the MathWorks, Inc.
  23. % All Rights Reserved.
  24. %------------------------------------------------------------------------
  25.  
  26. inargs = '(a,b,c,d,Type,no)';
  27. eval(mkargs(inargs,nargin,'ss'))
  28.  
  29. [ma,na] = size(a);
  30. [md,nd] = size(d);
  31. [hsv,p,q] = hksv(a,b,c);
  32. %
  33. % ------ Model reduction based on your choice of TYPE:
  34. %
  35. if Type == 1
  36.    kk = no+1;
  37. end
  38. %
  39. if Type == 2
  40.    tails = 0;
  41.    kk = 1;
  42.    for i = ma:-1:1
  43.        tails = tails + hsv(i);
  44.        if 2*tails > no
  45.           kk = i + 1;
  46.           break
  47.        end
  48.    end
  49. end
  50. %
  51. if Type == 3
  52.    format short e
  53.    format compact
  54.    [mhsv,nhsv] = size(hsv);
  55.    if mhsv < 60
  56.       disp('    Hankel Singular Values:')
  57.       hsv'
  58.       for i = 1:mhsv
  59.         if hsv(i) == 0
  60.            hsvp(i) = eps;
  61.         else
  62.            hsvp(i) = hsv(i);
  63.         end
  64.       end
  65.       disp(' ')
  66.       disp('                              (strike a key to see the plot ...)')
  67.       pause
  68.       subplot
  69.       plot(20*log10(hsvp),'--');hold
  70.       plot(20*log10(hsvp),'*');grid;hold
  71.       ylabel('DB')
  72.       title('Hankel Singular Values')
  73.       pause
  74.       no = input('Please assign the k-th index for k-th order model reduction: ');
  75.    else
  76.       disp('    Hankel Singular Values:')
  77.       hsv(1:60,:)'
  78.       disp('                              (strike a key for more ...)')
  79.       pause
  80.       hsv(61:mhsv,:)'
  81.       for i = 1:mhsv
  82.         if hsv(i) == 0
  83.            hsvp(i) = eps;
  84.         else
  85.            hsvp(i) = hsv(i);
  86.         end
  87.       end
  88.       disp(' ')
  89.       disp('                              (strike a key to see the plot ...)')
  90.       pause
  91.       subplot
  92.       plot(20*log10(hsvp),'--');hold
  93.       plot(20*log10(hsvp),'*');grid;hold
  94.       ylabel('DB')
  95.       title('Hankel Singular Values')
  96.       pause
  97.       no = input('Please assign the k-th index for k-th order model reduction: ');
  98.    end
  99.    format loose
  100.    kk = no + 1;
  101. end
  102. %
  103. % ------ Save all the states:
  104. %
  105. if kk > na 
  106.    ahed = a; bhed = b; ched = c; dhed = d;
  107.    slbig = eye(na); srbig = eye(na);
  108.    aug = [0 0];
  109.    return 
  110. end
  111. %
  112. % ------ Disgard all the states:
  113. %
  114. if kk == 1
  115.    ahed = zeros(ma,na);   bhed = zeros(ma,nd);
  116.    ched = zeros(md,na);   dhed = zeros(md,nd);
  117.    slbig = []; srbig = [];
  118.    bnd = 2*sum(hsv); 
  119.    aug = [na bnd];
  120.    return
  121. end 
  122. %
  123. % ------ k-th order Schur balanced model reduction:
  124. %
  125. bnd = 2*sum(hsv(kk:na));
  126. strm = na-kk+1;
  127. aug = [strm bnd];
  128. %
  129. % ------ Find the left-eigenspace basis :
  130. %
  131. ro = (hsv(kk-1)^2+hsv(kk)^2)/2.;
  132. gammaa = p*q-ro*eye(na);
  133. [va,ta,msa] = blkrsch(gammaa,1,na-kk+1);
  134. vlbig = va(:,(na-kk+2):na);
  135. %
  136. % ------ Find the right-eigenspace basis :
  137. %
  138. gammad = -gammaa;
  139. [vd,td,msd] = blkrsch(gammad,1,kk-1);
  140. vrbig = vd(:,1:kk-1);
  141. %
  142. % ------ Find the similarity transformation :
  143. %
  144. ee = vlbig'*vrbig;
  145. [ue,se,ve] = svd(ee);
  146. %
  147. seih = diag(ones(kk-1,1)./sqrt(diag(se)));
  148. slbig = vlbig*ue*seih;
  149. srbig = vrbig*ve*seih;
  150. %
  151. ahed = slbig'*a*srbig;
  152. bhed = slbig'*b;
  153. ched = c*srbig;
  154. dhed = d;
  155. %
  156. if xsflag
  157.    aheh = mksys(ahed,bhed,ched,dhed);
  158.    bhed = totbnd;
  159.    ched = hsv;
  160.    dhed = slbig; 
  161.    aug  = srbig;
  162. end
  163. %
  164. % ------ End of SCHBAL.M --- RYC/MGS 9/11/87 %