home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / zgfslv.m < prev    next >
Text File  |  1999-03-05  |  2KB  |  65 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 x = zgfslv(n,m,p,b)
  18.   # x = zgfslv(n,m,p,b)
  19.   # solve system of equations for dense zgep problem
  20.   
  21.   # Written by A. Scotte Hodel
  22.   # Converted to Octave by R Bruce Tenison, July 3, 1994
  23.  
  24.   nmp = n+m+p;
  25.   gam1 = (2*n)+m+p;    gam2 = n+p;     gam3 = n+m;
  26.  
  27.   G1 = givens(sqrt(m),-sqrt(p))';
  28.   G2 = givens(m+p,sqrt(n*(m+p)))';
  29.  
  30.   x = b;
  31.  
  32.   # 1) U1 e^n = sqrt(n)e_1^n
  33.   # 2) U2 e^m = sqrt(m)e_1^m
  34.   # 3) U3 e^p = sqrt(p)e_1^p
  35.   xdx1 = 1:n; xdx2 = n+(1:m); xdx3 = n+m+(1:p);
  36.   x(xdx1,1) = zgshsr(x(xdx1,1));
  37.   x(xdx2,1) = zgshsr(x(xdx2,1));
  38.   x(xdx3,1) = zgshsr(x(xdx3,1));
  39.  
  40.   # 4) Givens rotations to reduce stray non-zero elements
  41.   idx1 = [n+1,n+m+1];     idx2 = [1,n+1];
  42.   x(idx1) = G1'*x(idx1);
  43.   x(idx2) = G2'*x(idx2);
  44.  
  45.   # 6) Scale x, then back-transform to get x
  46.   en = ones(n,1);  em = ones(m,1);   ep = ones(p,1);
  47.   lam = [gam1*en;gam2*em;gam3*ep]; 
  48.   lam(1) = n+m+p; 
  49.   lam(n+1) = 1;       # dummy value to avoid divide by zero
  50.   lam(n+m+1)=n+m+p;
  51.  
  52.   x = x ./ lam;       x(n+1) = 0;  # minimum norm solution
  53.  
  54.   # back transform now.
  55.   x(idx2) = G2*x(idx2);
  56.   x(idx1) = G1*x(idx1);
  57.   x(xdx3,1) = zgshsr(x(xdx3,1));
  58.   x(xdx2,1) = zgshsr(x(xdx2,1));
  59.   x(xdx1,1) = zgshsr(x(xdx1,1));
  60.  
  61. endfunction
  62.  
  63.