home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / zginit.m < prev    next >
Text File  |  1999-03-05  |  2KB  |  88 lines

  1. # Copyright (C) 1996,1998 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 zz = zginit(a,b,c,d)
  18.   # zz = zginit(a,b,c,d)
  19.   # construct right hand side vector zz
  20.   # for the zero-computation generalized eigenvalue problem
  21.   # balancing procedure
  22.   # called by zgepbal
  23.   # References:
  24.   # ZGEP: Hodel, "Computation of Zeros with Balancing," Linear Algebra and
  25.   #              its Applications, 1993
  26.   # Generalized CG: Golub and Van Loan, "Matrix Computations, 2nd ed" 1989
  27.   
  28.   # A. S. Hodel July 24 1992
  29.   # Conversion to Octave by R. Bruce Tenison, July 3, 1994
  30.  
  31.   [nn,mm] = size(b);
  32.   [pp,mm] = size(d);
  33.  
  34.   nmp = nn+mm+pp;
  35.  
  36.   # set up log vector zz
  37.   zz = zeros(nmp,1);
  38.  
  39.   # zz part 1:
  40.   for i=1:nn
  41.     # nonzero off diagonal entries of a
  42.     if(nn > 1)
  43.       nidx = complement(i,1:nn);
  44.       a_row_i = a(i,nidx);                 a_col_i = a(nidx,i);
  45.       arnz = a_row_i(find(a_row_i != 0));  acnz = a_col_i(find(a_col_i != 0));
  46.     else
  47.       arnz = acnz = [];
  48.     endif
  49.  
  50.     # row of b
  51.     bidx = find(b(i,:) != 0);
  52.     b_row_i = b(i,bidx);
  53.  
  54.     # column of c
  55.     cidx = find(c(:,i) != 0);
  56.     c_col_i = c(cidx,i);
  57.    
  58.     # sum the entries
  59.     zz(i) = sum(log(abs(acnz))) - sum(log(abs(arnz))) ...
  60.             - sum(log(abs(b_row_i))) + sum(log(abs(c_col_i)));
  61.   endfor
  62.  
  63.   # zz part 2:
  64.   bd = [b;d];
  65.   for i=1:mm
  66.     i1 = i+nn;
  67.  
  68.     # column of [b;d]
  69.     bdidx = find(bd(:,i) != 0);
  70.     bd_col_i = bd(bdidx,i);
  71.     zz(i1) = sum(log(abs(bd_col_i)));
  72.   endfor
  73.  
  74.   # zz part 3:
  75.   cd = [c, d];
  76.   for i=1:pp
  77.     i1 = i+nn+mm;
  78.     cdidx = find(cd(i,:) != 0);
  79.     cd_row_i = cd(i,cdidx);
  80.     zz(i1) = -sum(log(abs(cd_row_i)));
  81.   endfor
  82.  
  83.   # now set zz as log base 2
  84.   zz = zz*(1/log(2));
  85. endfunction
  86.