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

  1. function [am,bm,cm,dm,totbnd,hsv] = schmr(Z1,Z2,Z3,Z4,Z5,Z6)
  2. % [SS_M,TOTBND,HSV] = SCHMR(SS_,TYPE,NO) or
  3. % [AM,BM,CM,DM,TOTBND,HSV]=SCHMR(A,B,C,D,TYPE,NO) performs Schur method
  4. %    model reduction on G(s):=(a,b,c,d) such that the infinity-norm
  5. %    of the error (Ghed(s) - G(s)) <= sum of the 2(n-k) smaller Hankel
  6. %    singular values. For unstable G(s) the algorithm works by first 
  7. %    splitting G(s) into a sum of stable and antistable part. 
  8. %   Based on the "TYPE" selected, you have the following options:
  9. %
  10. %    1). TYPE = 1  --- no: size "k" of the reduced order model.
  11. %
  12. %    2). TYPE = 2  --- find a k-th order model such that the total error 
  13. %                      is less than "no".
  14. %
  15. %    3). TYPE = 3  --- disply all the Hankel SV prompt for "k" (in this
  16. %                      case, no need to specify "no").
  17. %
  18. %    TOTBND = Error bound, HSV = Hankel Singular Values.
  19.  
  20. % R. Y. Chiang & M. G. Safonov 9/13/87
  21. % Copyright (c) 1988 by the MathWorks, Inc.
  22. % All Rights Reserved.
  23. % ------------------------------------------------------------------------
  24. %
  25. disp('  ');
  26. disp('        - - Working on Schur Balanced Model Reduction - -');
  27.  
  28. inargs = '(a,b,c,d,Type,no)';
  29. eval(mkargs(inargs,nargin,'ss'))
  30.  
  31. if Type == 3
  32.    no = 0;
  33. end
  34. [ra,ca] = size(a);
  35. [ee,dd] = eig(a); 
  36. %
  37. % ------ Find the no. of stable roots :
  38. %
  39. m = 0;
  40. for k = 1 : ra
  41.     if real(dd(k,k)) < 0
  42.         m = m + 1;
  43.     end
  44. end
  45. %
  46. % ------ If completely stable :
  47. %
  48. kk = -1;
  49. if m == ra
  50.    [am,bm,cm,dm,augl,hsv,slbig,srbig] = schbal(a,b,c,d,Type,no);
  51.    kk = 1;
  52.    augr = [0 0];
  53.    totbnd = augl(1,2);
  54. end
  55. %
  56. % ------ If completely unstable :
  57. %
  58. if m == 0.
  59.    [am,bm,cm,dm,augr,hsv,slbig,srbig] = schbal(-a,-b,c,d,Type,no);
  60.    am = -am; bm = -bm; 
  61.    kk = 1;
  62.    augl = [0 0];
  63.    totbnd = augr(1,2);
  64. end
  65. %
  66. % ------ If having both stable & unstable parts :
  67. %
  68. if kk < 0
  69.   [al,bl,cl,dl,ar,br,cr,dr,msat] = stabproj(a,b,c,d);
  70.   [hsvl,pl,ql] = hksv(al,bl,cl);
  71.   [hsvr,pr,qr] = hksv(-ar,-br,cr);
  72.   hsv = [hsvl;hsvr];
  73.   [hsv,index] = sort(hsv);
  74.   hsv = hsv(ra:-1:1,:);
  75.   index = index(ra:-1:1,:);
  76.   if Type == 1
  77.       nor = 0;
  78.       for i = 1:no
  79.           if index(i) > msat
  80.              nor = nor + 1;           
  81.           end
  82.       end
  83.      nol = no-nor;
  84.    end
  85.    if Type == 2
  86.       tol = no;
  87.       tails = 0;
  88.       for i = ra:-1:1
  89.           tails = tails + hsv(i);
  90.           if 2*tails > tol
  91.              no = i;
  92.              break    
  93.           end
  94.       end
  95.       nor = 0;
  96.       for i = 1:no
  97.           if index(i) > msat
  98.              nor = nor + 1;           
  99.           end
  100.       end
  101.       nol = no-nor;
  102.       Type = 1;
  103.    end
  104.    if Type == 3
  105.       nol = no; nor = no;
  106.    end
  107.    [alf,blf,clf,dlf,augl,hsvl,tll,tlr] = schbal(al,bl,cl,dl,Type,nol);
  108.    [arf,brf,crf,drf,augr,hsvr,trl,trr] = schbal(-ar,-br,cr,dr,Type,nor);
  109.    arf = -arf;
  110.    brf = -brf;
  111.    totbnd = augl(1,2)+augr(1,2);
  112.    hsv = [hsvl;hsvr];
  113.    [am,bm,cm,dm] = addss(alf,blf,clf,dlf,arf,brf,crf,drf);
  114.    [ral,cal] = size(al); [rar,car] = size(ar);
  115.    if augl(1,1) == ral
  116.       am = arf; bm = brf; cm = crf; dm = d;
  117.    end
  118.    if augr(1,1) == rar
  119.       am = alf; bm = blf; cm = clf; dm = d;
  120.    end
  121. end
  122. %
  123. if xsflag
  124.    am = mksys(am,bm,cm,dm);
  125.    bm = totbnd;
  126.    cm = hsv;
  127. end
  128. %
  129. nn = augl(1,1) + augr(1,1);
  130. disp(' ')
  131. disp(['               ' int2str(nn), '    states removed !!'])
  132. %
  133. % ------- End of SCHMR.M --- RYC/MGS 9/13/87 %