home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / zgreduce.m < prev    next >
Text File  |  1999-04-29  |  4KB  |  142 lines

  1. # Copyright (C) 1996 A. Scottedward Hodel 
  2. #
  3. # This file is part of Octave. 
  4. #
  5. # Octave is free software; you can redistribute it and/or modify it 
  6. # under the terms of the GNU General Public License as published by the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function retsys = zgreduce(Asys,meps)
  18. # function retsys = zgreduce(Asys,meps)
  19. # implementation of procedure REDUCE in (Emami-Naeini and Van Dooren, 
  20. # Automatica, # 1982).
  21. #
  22. # used internally in tzero; minimal argument checking performed
  23.  
  24. # SYS_INTERNAL accesses members of system data structure
  25.  
  26. is_digit(Asys);        # make sure it's pure digital/continuous
  27.  
  28. exit_1 = 0;            # exit_1 = 1 or 2 on exit of loop
  29.  
  30. if(Asys.n + Asys.nz == 0)
  31.   exit_1 = 2;            # there are no finite zeros
  32. endif
  33.  
  34. while (! exit_1)
  35.   [Q,R,Pi] = qr(Asys.d);        # compress rows of D
  36.   Asys.d = Q'*Asys.d;
  37.   Asys.c = Q'*Asys.c;
  38.  
  39.   # check row norms of Asys.d
  40.   [sig,tau] = zgrownor(Asys.d,meps);
  41.  
  42.   #disp("=======================================")
  43.   #disp(["zgreduce: meps=",num2str(meps), ", sig=",num2str(sig), ...
  44.   #    ", tau=",num2str(tau)])
  45.   #sysout(Asys)
  46.  
  47.   if(tau == 0)
  48.     exit_1 = 1;        # exit_1 - reduction complete and correct
  49.   else
  50.     Cb = Db = [];
  51.     if(sig)
  52.       Cb = Asys.c(1:sig,:);
  53.       Db = Asys.d(1:sig,:);
  54.     endif
  55.     Ct =Asys.c(sig+(1:tau),:);
  56.  
  57.     # compress columns of Ct
  58.     [pp,nn] = size(Ct);
  59.     rvec = nn:-1:1;
  60.     [V,Sj,Pi] = qr(Ct');
  61.     V = V(:,rvec);
  62.     [rho,gnu] = zgrownor(Sj,meps);
  63.  
  64.     #disp(["zgreduce: rho=",num2str(rho),", gnu=",num2str(gnu)])
  65.     #Cb
  66.     #Db
  67.     #Ct
  68.     #Sj'
  69.  
  70.     if(rho == 0)
  71.       exit_1 = 1;    # exit_1 - reduction complete and correct
  72.     elseif(gnu == 0)
  73.       exit_1 = 2;    # there are no zeros at all
  74.     else
  75.       mu = rho + sig;
  76.  
  77.       # update system with Q
  78.       M = [Asys.a , Asys.b ];
  79.       [nn,mm] = size(Asys.b);
  80.  
  81.       pp = rows(Asys.d);
  82.       Vm =[V,zeros(nn,mm) ; zeros(mm,nn), eye(mm)];
  83.       if(sig)
  84.         M = [M; Cb, Db];
  85.         Vs =[V',zeros(nn,sig) ; zeros(sig,nn), eye(sig)];
  86.       else
  87.         Vs = V';
  88.       endif
  89.       #disp("zgreduce: before transform: M=");
  90.       #M
  91.       #Vs   
  92.       #Vm
  93.  
  94.       M = Vs*M*Vm;
  95.       
  96.       #disp("zgreduce: after transform: M=");
  97.       #M
  98.  
  99.       #disp("debugging code:")
  100.       #Mtmp = [Asys.a Asys.b; Asys.c Asys.d]
  101.       #Vl = [V', zeros(nn,mm); zeros(mm,nn),Q]
  102.       #Vr =[V,zeros(nn,mm) ; zeros(mm,nn), eye(mm)];
  103.       #Mtmpf = Vl*Mtmp*Vr
  104.  
  105.       idx = 1:gnu;
  106.       jdx = nn + (1:mm);
  107.       sdx = gnu + (1:mu);
  108.  
  109.       Asys.a = M(idx,idx);
  110.       Asys.b = M(idx,jdx);
  111.       Asys.c = M(sdx,idx);
  112.       Asys.d = M(sdx,jdx);
  113.  
  114.       #disp(["zgreduce: resulting system: nn =",num2str(nn)," mu=",num2str(mu)])
  115.       #sysout(Asys)
  116.       #idx
  117.       #jdx
  118.       #sdx
  119.     endif
  120.   endif
  121. endwhile
  122.  
  123. #disp(["zgreduce: while loop done: exit_1=",num2str(exit_1)]);
  124.  
  125. if(exit_1 == 2)
  126.   # there are no zeros at all!
  127.   Asys.a = Asys.b = Asys.c = [];
  128. endif
  129.  
  130. # update dimensions
  131. if(is_digit(Asys))
  132.   Asys.nz = rows(Asys.a);
  133. else
  134.   Asys.n = rows(Asys.a);
  135. endif
  136.  
  137. retsys = Asys;
  138.  
  139. endfunction
  140.