1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
## Copyright (C) 1996, 1998, 2000, 2005, 2007
## Auburn University. All rights reserved.
##
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {} zgfslv (@var{n}, @var{m}, @var{p}, @var{b})
## Solve system of equations for dense zgep problem.
## @end deftypefn
## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu>
## Converted to Octave by R Bruce Tenison, July 3, 1994
function x = zgfslv (n, m, p, b)
if (nargin != 4)
print_usage ();
endif
nmp = n+m+p;
gam1 = (2*n)+m+p;
gam2 = n+p;
gam3 = n+m;
G1 = givens (sqrt (m), -sqrt (p))';
G2 = givens (m+p, sqrt (n*(m+p)))';
x = b;
## 1) U1 e^n = sqrt(n)e_1^n
## 2) U2 e^m = sqrt(m)e_1^m
## 3) U3 e^p = sqrt(p)e_1^p
xdx1 = 1:n;
xdx2 = n+(1:m);
xdx3 = n+m+(1:p);
x(xdx1,1) = zgshsr (x(xdx1,1));
x(xdx2,1) = zgshsr (x(xdx2,1));
x(xdx3,1) = zgshsr (x(xdx3,1));
## 4) Givens rotations to reduce stray non-zero elements
idx1 = [n+1, n+m+1];
idx2 = [1, n+1];
x(idx1) = G1'*x(idx1);
x(idx2) = G2'*x(idx2);
## 6) Scale x, then back-transform to get x
en = ones (n, 1);
em = ones (m, 1);
ep = ones (p, 1);
lam = [gam1*en; gam2*em; gam3*ep];
lam(1) = n+m+p;
lam(n+1) = 1; # dummy value to avoid divide by zero
lam(n+m+1) = n+m+p;
x = x ./ lam;
x(n+1) = 0; # minimum norm solution
## back transform now.
x(idx2) = G2*x(idx2);
x(idx1) = G1*x(idx1);
x(xdx3,1) = zgshsr (x(xdx3,1));
x(xdx2,1) = zgshsr (x(xdx2,1));
x(xdx1,1) = zgshsr (x(xdx1,1));
endfunction
|