home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / zgpbal.m < prev    next >
Text File  |  1999-03-05  |  3KB  |  106 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] = zgpbal(Asys)
  18.   # function [retsys] = zgpbal(Asys)
  19.   #
  20.   # used internally in tzero; minimal argument checking performed
  21.   #
  22.   # implementation of zero computation generalized eigenvalue problem 
  23.   # balancing method (Hodel and Tiller, Allerton Conference, 1991)
  24.   # Based on Ward's balancing algorithm (SIAM J. Sci Stat. Comput., 1981)
  25.   #
  26.   # zgpbal computes a state/input/output weighting that attempts to 
  27.   # reduced the range of the magnitudes of the nonzero elements of [a,b,c,d]
  28.   # The weighting uses scalar multiplication by powers of 2, so no roundoff
  29.   # will occur.  
  30.   #
  31.   # zgpbal should be followed by zgpred
  32.   # References:
  33.   # ZGEP: Hodel, "Computation of Zeros with Balancing," 1992, Linear Algebra
  34.   # and its Applications
  35.   # Generalized CG: Golub and Van Loan, "Matrix Computations, 2nd ed" 1989
  36.   
  37.   # A. S. Hodel July 24 1992
  38.   # Conversion to Octave by R. Bruce Tenison July 3, 1994
  39.  
  40.   if( (nargin != 1) | (!is_struct(Asys)))
  41.     usage("retsys = zgpbal(Asys)");
  42.   endif
  43.  
  44.   Asys = sysupdate(Asys,"ss");
  45.   [a,b,c,d] = sys2ss(Asys);
  46.  
  47.   [nn,mm,pp] = abcddim(a,b,c,d);
  48.   
  49.   np1 = nn+1;
  50.   nmp = nn+mm+pp;
  51.  
  52.   # set up log vector zz, incidence matrix ff
  53.   zz = zginit(a,b,c,d);
  54.  
  55.   #disp("zgpbal: zginit returns")
  56.   #zz
  57.   #disp("/zgpbal")
  58.  
  59.   if (norm(zz))
  60.     # generalized conjugate gradient approach
  61.     xx = zgscal(a,b,c,d,zz,nn,mm,pp);
  62.     
  63.     for i=1:nmp
  64.       xx(i) = floor(xx(i)+0.5);
  65.       xx(i) = 2.0^xx(i);
  66.     endfor
  67.     
  68.     # now scale a
  69.     # block 1: a = sigma a inv(sigma)
  70.     for i=1:nn
  71.       a(i,1:nn) = a(i,1:nn)*xx(i);
  72.       a(1:nn,i) = a(1:nn,i)/xx(i);
  73.     endfor
  74.     # block 2: b= sigma a phi
  75.     for j=1:mm
  76.       j1 = j+nn;
  77.       b(1:nn,j) = b(1:nn,j)*xx(j1);
  78.     endfor
  79.     for i=1:nn
  80.       b(i,1:mm) = b(i,1:mm)*xx(i);
  81.     endfor
  82.     for i=1:pp
  83.       i1 = i+nn+mm;
  84.       #   block 3: c = psi C inv(sigma)
  85.       c(i,1:nn) = c(i,1:nn)*xx(i1);
  86.     endfor
  87.     for j=1:nn
  88.       c(1:pp,j) = c(1:pp,j)/xx(j);
  89.     endfor
  90.     #   block 4: d = psi D phi
  91.     for j=1:mm
  92.       j1 = j+nn;
  93.       d(1:pp,j) = d(1:pp,j)*xx(j1);
  94.     endfor
  95.     for i=1:pp
  96.       i1 = i + nn + mm;
  97.       d(i,1:mm) = d(i,1:mm)*xx(i1);
  98.     endfor
  99.   endif
  100.   
  101.   retsys = ss2sys(a,b,c,d);
  102. endfunction
  103.  
  104.