519
|
1 // f-qzval.cc -*- C++ -*- |
44
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1993, 1994, 1995 John W. Eaton |
44
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
44
|
21 |
|
22 */ |
|
23 |
|
24 // Written by A. S. Hodel <scotte@eng.auburn.edu> |
|
25 |
240
|
26 #ifdef HAVE_CONFIG_H |
1192
|
27 #include <config.h> |
44
|
28 #endif |
|
29 |
1342
|
30 #include <cfloat> |
112
|
31 |
1352
|
32 #include "CColVector.h" |
453
|
33 #include "dColVector.h" |
1352
|
34 #include "dMatrix.h" |
234
|
35 #include "f77-uscore.h" |
44
|
36 |
1352
|
37 #include "defun-dld.h" |
|
38 #include "error.h" |
|
39 #include "gripes.h" |
|
40 #include "help.h" |
44
|
41 #include "tree-const.h" |
|
42 #include "user-prefs.h" |
636
|
43 #include "utils.h" |
44
|
44 |
47
|
45 extern "C" |
|
46 { |
1255
|
47 int F77_FCN (qzhes, QZHES) (const int&, const int&, double*, |
|
48 double*, const long&, double*); |
44
|
49 |
1255
|
50 int F77_FCN (qzit, QZIT) (const int&, const int&, double*, double*, |
|
51 const double&, const long&, double*, |
|
52 int&); |
44
|
53 |
1255
|
54 int F77_FCN (qzval, QZVAL) (const int&, const int&, double*, |
|
55 double*, double*, double*, double*, |
|
56 const long&, double*); |
47
|
57 } |
44
|
58 |
876
|
59 DEFUN_DLD_BUILTIN ("qzval", Fqzval, Sqzval, 3, 1, |
519
|
60 "X = qzval (A, B)\n\ |
|
61 \n\ |
|
62 compute generalized eigenvalues of the matrix pencil (A - lambda B).\n\ |
|
63 A and B must be real matrices.") |
44
|
64 { |
497
|
65 Octave_object retval; |
44
|
66 |
712
|
67 int nargin = args.length (); |
|
68 |
|
69 if (nargin != 2 || nargout > 1) |
519
|
70 { |
876
|
71 print_usage ("qzval"); |
519
|
72 return retval; |
|
73 } |
|
74 |
712
|
75 tree_constant arg_a = args(0); |
|
76 tree_constant arg_b = args(1); |
636
|
77 |
|
78 int a_nr = arg_a.rows(); |
|
79 int a_nc = arg_a.columns(); |
44
|
80 |
636
|
81 int b_nr = arg_b.rows(); |
|
82 int b_nc = arg_b.columns(); |
718
|
83 |
876
|
84 int arg_a_is_empty = empty_arg ("qzval", a_nr, a_nc); |
|
85 int arg_b_is_empty = empty_arg ("qzval", b_nr, b_nc); |
718
|
86 |
|
87 if (arg_a_is_empty > 0 && arg_b_is_empty > 0) |
|
88 return Matrix (); |
|
89 else if (arg_a_is_empty || arg_b_is_empty) |
636
|
90 return retval; |
44
|
91 |
|
92 // Arguments are not empty, so check for correct dimensions. |
|
93 |
636
|
94 if (a_nr != a_nc || b_nr != b_nc) |
|
95 { |
876
|
96 gripe_square_matrix_required ("qzval: first two parameters:"); |
636
|
97 return retval; |
|
98 } |
|
99 |
|
100 if (a_nr != b_nr) |
|
101 { |
|
102 gripe_nonconformant (); |
|
103 return retval; |
|
104 } |
44
|
105 |
|
106 // Dimensions look o.k., let's solve the problem. |
|
107 |
636
|
108 if (arg_a.is_complex_type () || arg_b.is_complex_type ()) |
|
109 { |
876
|
110 error ("qzval: cannot yet do complex matrix arguments\n"); |
636
|
111 return retval; |
|
112 } |
44
|
113 |
|
114 // Do everything in real arithmetic. |
|
115 |
636
|
116 Matrix jnk (a_nr, a_nr, 0.0); |
44
|
117 |
636
|
118 ColumnVector alfr (a_nr); |
|
119 ColumnVector alfi (a_nr); |
|
120 ColumnVector beta (a_nr); |
44
|
121 |
636
|
122 long matz = 0; |
|
123 int info; |
44
|
124 |
|
125 // XXX FIXME ??? XXX |
636
|
126 double eps = DBL_EPSILON; |
|
127 |
|
128 Matrix ca = arg_a.matrix_value (); |
44
|
129 |
636
|
130 if (error_state) |
|
131 return retval; |
|
132 |
|
133 Matrix cb = arg_b.matrix_value (); |
|
134 |
|
135 if (error_state) |
|
136 return retval; |
44
|
137 |
|
138 // Use EISPACK qz functions. |
|
139 |
1255
|
140 F77_FCN (qzhes, QZHES) (a_nr, a_nr, ca.fortran_vec (), |
|
141 cb.fortran_vec (), matz, |
|
142 jnk.fortran_vec ()); |
44
|
143 |
1255
|
144 F77_FCN (qzit, QZIT) (a_nr, a_nr, ca.fortran_vec (), |
|
145 cb.fortran_vec (), eps, matz, |
|
146 jnk.fortran_vec (), info); |
44
|
147 |
636
|
148 if (info) |
876
|
149 error ("qzval: trouble in qzit, info = %d", info); |
44
|
150 |
1255
|
151 F77_FCN (qzval, QZVAL) (a_nr, a_nr, ca.fortran_vec (), |
|
152 cb.fortran_vec (), alfr.fortran_vec (), |
|
153 alfi.fortran_vec (), beta.fortran_vec (), |
|
154 matz, jnk.fortran_vec ()); |
44
|
155 |
|
156 // Count and extract finite generalized eigenvalues. |
|
157 |
636
|
158 int i; |
|
159 int cnt = 0; |
|
160 |
|
161 Complex Im (0, 1); |
44
|
162 |
636
|
163 for (i = 0; i < a_nr; i++) |
|
164 if (beta (i) != 0) |
|
165 cnt++; |
44
|
166 |
636
|
167 ComplexColumnVector cx (cnt, 0.0); |
|
168 |
|
169 for (i = 0; i < a_nr; i++) |
|
170 { |
|
171 if (beta (i) != 0) |
|
172 { |
44
|
173 |
|
174 // Finite generalized eigenvalue. |
|
175 |
636
|
176 cnt--; |
|
177 cx (cnt) = (alfr (i) + Im * alfi (i)) / beta (i); |
44
|
178 } |
|
179 } |
636
|
180 |
|
181 retval = cx; |
|
182 |
44
|
183 return retval; |
|
184 } |
|
185 |
|
186 /* |
|
187 ;;; Local Variables: *** |
|
188 ;;; mode: C++ *** |
|
189 ;;; page-delimiter: "^/\\*" *** |
|
190 ;;; End: *** |
|
191 */ |