519
|
1 // f-qzval.cc -*- C++ -*- |
44
|
2 /* |
|
3 |
453
|
4 Copyright (C) 1993, 1994 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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 // Written by A. S. Hodel <scotte@eng.auburn.edu> |
|
25 |
240
|
26 #ifdef HAVE_CONFIG_H |
|
27 #include "config.h" |
44
|
28 #endif |
|
29 |
112
|
30 #include <float.h> |
|
31 |
453
|
32 #include "dMatrix.h" |
|
33 #include "dColVector.h" |
|
34 #include "CColVector.h" |
234
|
35 #include "f77-uscore.h" |
44
|
36 |
|
37 #include "tree-const.h" |
|
38 #include "user-prefs.h" |
|
39 #include "gripes.h" |
|
40 #include "error.h" |
636
|
41 #include "utils.h" |
544
|
42 #include "help.h" |
519
|
43 #include "defun-dld.h" |
44
|
44 |
47
|
45 extern "C" |
|
46 { |
|
47 int F77_FCN (qzhes) (const int*, const int*, double*, double*, const |
|
48 long*, double*); |
44
|
49 |
47
|
50 int F77_FCN (qzit) (const int*, const int*, double*, double*, const |
|
51 double*, const long*, double*, int*); |
44
|
52 |
47
|
53 int F77_FCN (qzval) (const int*, const int*, double*, double*, |
|
54 double*, double*, double*, const long*, double*); |
|
55 } |
44
|
56 |
701
|
57 DEFUN_DLD_BUILTIN ("qzvalue", Fqzvalue, Sqzvalue, 3, 1, |
519
|
58 "X = qzval (A, B)\n\ |
|
59 \n\ |
|
60 compute generalized eigenvalues of the matrix pencil (A - lambda B).\n\ |
|
61 A and B must be real matrices.") |
44
|
62 { |
497
|
63 Octave_object retval; |
44
|
64 |
712
|
65 int nargin = args.length (); |
|
66 |
|
67 if (nargin != 2 || nargout > 1) |
519
|
68 { |
|
69 print_usage ("qzvalue"); |
|
70 return retval; |
|
71 } |
|
72 |
712
|
73 tree_constant arg_a = args(0); |
|
74 tree_constant arg_b = args(1); |
636
|
75 |
|
76 int a_nr = arg_a.rows(); |
|
77 int a_nc = arg_a.columns(); |
44
|
78 |
636
|
79 int b_nr = arg_b.rows(); |
|
80 int b_nc = arg_b.columns(); |
|
81 |
|
82 if (empty_arg ("qzvalue", a_nr, a_nc) < 0 |
|
83 || empty_arg ("qzvalue", b_nr, b_nc) < 0) |
|
84 return retval; |
44
|
85 |
|
86 // Arguments are not empty, so check for correct dimensions. |
|
87 |
636
|
88 if (a_nr != a_nc || b_nr != b_nc) |
|
89 { |
|
90 gripe_square_matrix_required ("qzvalue: first two parameters:"); |
|
91 return retval; |
|
92 } |
|
93 |
|
94 if (a_nr != b_nr) |
|
95 { |
|
96 gripe_nonconformant (); |
|
97 return retval; |
|
98 } |
44
|
99 |
|
100 // Dimensions look o.k., let's solve the problem. |
|
101 |
636
|
102 if (arg_a.is_complex_type () || arg_b.is_complex_type ()) |
|
103 { |
|
104 error ("qzvalue: cannot yet do complex matrix arguments\n"); |
|
105 return retval; |
|
106 } |
44
|
107 |
|
108 // Do everything in real arithmetic. |
|
109 |
636
|
110 Matrix jnk (a_nr, a_nr, 0.0); |
44
|
111 |
636
|
112 ColumnVector alfr (a_nr); |
|
113 ColumnVector alfi (a_nr); |
|
114 ColumnVector beta (a_nr); |
44
|
115 |
636
|
116 long matz = 0; |
|
117 int info; |
44
|
118 |
|
119 // XXX FIXME ??? XXX |
636
|
120 double eps = DBL_EPSILON; |
|
121 |
|
122 Matrix ca = arg_a.matrix_value (); |
44
|
123 |
636
|
124 if (error_state) |
|
125 return retval; |
|
126 |
|
127 Matrix cb = arg_b.matrix_value (); |
|
128 |
|
129 if (error_state) |
|
130 return retval; |
44
|
131 |
|
132 // Use EISPACK qz functions. |
|
133 |
636
|
134 F77_FCN (qzhes) (&a_nr, &a_nr, ca.fortran_vec (), |
|
135 cb.fortran_vec (), &matz, jnk.fortran_vec ()); |
44
|
136 |
636
|
137 F77_FCN (qzit) (&a_nr, &a_nr, ca.fortran_vec (), |
|
138 cb.fortran_vec (), &eps, &matz, |
|
139 jnk.fortran_vec (), &info); |
44
|
140 |
636
|
141 if (info) |
|
142 error ("qzvalue: trouble in qzit, info = %d", info); |
44
|
143 |
636
|
144 F77_FCN (qzval) (&a_nr, &a_nr, ca.fortran_vec (), |
|
145 cb.fortran_vec (), alfr.fortran_vec (), |
|
146 alfi.fortran_vec (), beta.fortran_vec (), |
|
147 &matz, jnk.fortran_vec ()); |
44
|
148 |
|
149 // Count and extract finite generalized eigenvalues. |
|
150 |
636
|
151 int i; |
|
152 int cnt = 0; |
|
153 |
|
154 Complex Im (0, 1); |
44
|
155 |
636
|
156 for (i = 0; i < a_nr; i++) |
|
157 if (beta (i) != 0) |
|
158 cnt++; |
44
|
159 |
636
|
160 ComplexColumnVector cx (cnt, 0.0); |
|
161 |
|
162 for (i = 0; i < a_nr; i++) |
|
163 { |
|
164 if (beta (i) != 0) |
|
165 { |
44
|
166 |
|
167 // Finite generalized eigenvalue. |
|
168 |
636
|
169 cnt--; |
|
170 cx (cnt) = (alfr (i) + Im * alfi (i)) / beta (i); |
44
|
171 } |
|
172 } |
636
|
173 |
|
174 retval = cx; |
|
175 |
44
|
176 return retval; |
|
177 } |
|
178 |
|
179 /* |
|
180 ;;; Local Variables: *** |
|
181 ;;; mode: C++ *** |
|
182 ;;; page-delimiter: "^/\\*" *** |
|
183 ;;; End: *** |
|
184 */ |