3431
|
1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved. |
|
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 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 ## for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301 USA. |
3431
|
19 |
|
20 ## -*- texinfo -*- |
3500
|
21 ## @deftypefn {Function File} {} zgfslv (@var{n}, @var{m}, @var{p}, @var{b}) |
3431
|
22 ## Solve system of equations for dense zgep problem. |
|
23 ## @end deftypefn |
|
24 |
|
25 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
26 ## Converted to Octave by R Bruce Tenison, July 3, 1994 |
|
27 |
|
28 function x = zgfslv (n, m, p, b) |
|
29 |
|
30 nmp = n+m+p; |
|
31 gam1 = (2*n)+m+p; gam2 = n+p; gam3 = n+m; |
|
32 |
|
33 G1 = givens(sqrt(m),-sqrt(p))'; |
|
34 G2 = givens(m+p,sqrt(n*(m+p)))'; |
|
35 |
|
36 x = b; |
|
37 |
|
38 ## 1) U1 e^n = sqrt(n)e_1^n |
|
39 ## 2) U2 e^m = sqrt(m)e_1^m |
|
40 ## 3) U3 e^p = sqrt(p)e_1^p |
|
41 xdx1 = 1:n; xdx2 = n+(1:m); xdx3 = n+m+(1:p); |
|
42 x(xdx1,1) = zgshsr(x(xdx1,1)); |
|
43 x(xdx2,1) = zgshsr(x(xdx2,1)); |
|
44 x(xdx3,1) = zgshsr(x(xdx3,1)); |
|
45 |
|
46 ## 4) Givens rotations to reduce stray non-zero elements |
|
47 idx1 = [n+1,n+m+1]; idx2 = [1,n+1]; |
|
48 x(idx1) = G1'*x(idx1); |
|
49 x(idx2) = G2'*x(idx2); |
|
50 |
|
51 ## 6) Scale x, then back-transform to get x |
|
52 en = ones(n,1); em = ones(m,1); ep = ones(p,1); |
|
53 lam = [gam1*en;gam2*em;gam3*ep]; |
|
54 lam(1) = n+m+p; |
|
55 lam(n+1) = 1; # dummy value to avoid divide by zero |
|
56 lam(n+m+1)=n+m+p; |
|
57 |
|
58 x = x ./ lam; x(n+1) = 0; # minimum norm solution |
|
59 |
|
60 ## back transform now. |
|
61 x(idx2) = G2*x(idx2); |
|
62 x(idx1) = G1*x(idx1); |
|
63 x(xdx3,1) = zgshsr(x(xdx3,1)); |
|
64 x(xdx2,1) = zgshsr(x(xdx2,1)); |
|
65 x(xdx1,1) = zgshsr(x(xdx1,1)); |
|
66 |
|
67 endfunction |
|
68 |