home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / zgfmul.m < prev    next >
Text File  |  1999-03-05  |  3KB  |  80 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 y = zgfmul(a,b,c,d,x)
  18.   # y = zgfmul(a,b,c,d,x)
  19.   # 
  20.   # Compute product of zgep incidence matrix F with vector x.
  21.   # Used by zgepbal (in zgscal) as part of generalized conjugate gradient
  22.   # iteration.
  23.   #
  24.   # References:
  25.   # ZGEP: Hodel, "Computation of Zeros with Balancing," Linear algebra and
  26.   #    its Applications, 1993
  27.   # Generalized CG: Golub and Van Loan, "Matrix Computations, 2nd ed" 1989
  28.   
  29.   # A. S. Hodel July 24 1992
  30.   # Conversion to Octave July 3, 1994
  31.   
  32.   [n,m] = size(b);
  33.   [p,m1] = size(c);
  34.   nm = n+m;
  35.   y = zeros(nm+p,1);
  36.  
  37.   # construct F column by column
  38.   for jj=1:n
  39.     Fj = zeros(nm+p,1);
  40.  
  41.     #rows 1:n: F1
  42.     aridx = complement(jj,find(a(jj,:) != 0)); 
  43.     acidx = complement(jj,find(a(:,jj) != 0));
  44.     bidx = find(b(jj,:) != 0);
  45.     cidx = find(c(:,jj) != 0);
  46.  
  47.     Fj(aridx) = Fj(aridx) - 1;      # off diagonal entries of F1
  48.     Fj(acidx) = Fj(acidx) - 1;
  49.     # diagonal entry of F1
  50.     Fj(jj) = length(aridx)+length(acidx) + length(bidx) + length(cidx);
  51.     
  52.     if(!isempty(bidx)) Fj(n+bidx) = 1;     endif # B' incidence
  53.     if(!isempty(cidx)) Fj(n+m+cidx) = -1;  endif # -C incidence
  54.     y = y + x(jj)*Fj;   # multiply by corresponding entry of x
  55.   endfor
  56.  
  57.   for jj=1:m
  58.     Fj = zeros(nm+p,1);
  59.     bidx = find(b(:,jj) != 0);   
  60.     if(!isempty(bidx)) Fj(bidx) = 1; endif     # B incidence
  61.     didx = find(d(:,jj) != 0);   
  62.     if(!isempty(didx)) Fj(n+m+didx) = 1; endif # D incidence
  63.     Fj(n+jj) = length(bidx) + length(didx);         # F2 is diagonal
  64.     y = y + x(n+jj)*Fj;   # multiply by corresponding entry of x
  65.   endfor
  66.  
  67.   for jj=1:p
  68.     Fj = zeros(nm+p,1);
  69.     cidx = find(c(jj,:) != 0);   
  70.     if(!isempty(cidx)) Fj(cidx) = -1; endif  # -C' incidence
  71.     didx = find(d(jj,:) != 0);   
  72.     if(!isempty(didx)) Fj(n+didx) = 1;  endif # D' incidence
  73.     Fj(n+m+jj) = length(cidx) + length(didx);     # F2 is diagonal
  74.     y = y + x(n+m+jj)*Fj;   # multiply by corresponding entry of x
  75.   endfor
  76.  
  77. endfunction
  78.