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" |
544
|
41 #include "help.h" |
519
|
42 #include "defun-dld.h" |
44
|
43 |
47
|
44 extern "C" |
|
45 { |
|
46 int F77_FCN (qzhes) (const int*, const int*, double*, double*, const |
|
47 long*, double*); |
44
|
48 |
47
|
49 int F77_FCN (qzit) (const int*, const int*, double*, double*, const |
|
50 double*, const long*, double*, int*); |
44
|
51 |
47
|
52 int F77_FCN (qzval) (const int*, const int*, double*, double*, |
|
53 double*, double*, double*, const long*, double*); |
|
54 } |
44
|
55 |
519
|
56 DEFUN_DLD ("qzvalue", Fqzvalue, Sqzvalue, 3, 1, |
|
57 "X = qzval (A, B)\n\ |
|
58 \n\ |
|
59 compute generalized eigenvalues of the matrix pencil (A - lambda B).\n\ |
|
60 A and B must be real matrices.") |
44
|
61 { |
497
|
62 Octave_object retval; |
44
|
63 |
519
|
64 int nargin = args.length (); |
|
65 |
|
66 if (nargin != 3 || nargout > 1) |
|
67 { |
|
68 print_usage ("qzvalue"); |
|
69 return retval; |
|
70 } |
|
71 |
497
|
72 tree_constant arga = args(1).make_numeric (); |
|
73 tree_constant argb = args(2).make_numeric(); |
44
|
74 |
91
|
75 if (arga.is_empty () || argb.is_empty ()) |
98
|
76 retval = vector_of_empties (nargout, "qzvalue"); |
44
|
77 else |
|
78 { |
|
79 |
|
80 // Arguments are not empty, so check for correct dimensions. |
|
81 |
|
82 int a_rows = arga.rows(); |
|
83 int a_cols = arga.columns(); |
|
84 int b_rows = argb.rows(); |
|
85 int b_cols = argb.columns(); |
|
86 |
|
87 if ((a_rows != a_cols) || (b_rows != b_cols)) |
|
88 { |
|
89 gripe_square_matrix_required ("qzvalue: first two parameters:"); |
|
90 return retval; |
|
91 } |
|
92 else if (a_rows != b_rows) |
|
93 { |
|
94 gripe_nonconformant (); |
|
95 return retval; |
|
96 } |
|
97 |
|
98 // Dimensions look o.k., let's solve the problem. |
|
99 |
497
|
100 retval.resize (nargout ? nargout : 1); |
44
|
101 |
|
102 if (arga.is_complex_type () || argb.is_complex_type ()) |
|
103 error ("qzvalue: cannot yet do complex matrix arguments\n"); |
|
104 else |
|
105 { |
|
106 |
|
107 // Do everything in real arithmetic. |
|
108 |
|
109 Matrix jnk (a_rows, a_rows, 0.0); |
|
110 |
|
111 ColumnVector alfr (a_rows); |
|
112 ColumnVector alfi (a_rows); |
|
113 ColumnVector beta (a_rows); |
|
114 |
|
115 long matz = 0; |
|
116 int info; |
|
117 |
|
118 // XXX FIXME ??? XXX |
|
119 double eps = DBL_EPSILON; |
|
120 |
628
|
121 Matrix ca = arga.matrix_value (); |
|
122 Matrix cb = argb.matrix_value (); |
44
|
123 |
|
124 // Use EISPACK qz functions. |
|
125 |
|
126 F77_FCN (qzhes) (&a_rows, &a_rows, ca.fortran_vec (), |
|
127 cb.fortran_vec (), &matz, jnk.fortran_vec ()); |
|
128 |
|
129 F77_FCN (qzit) (&a_rows, &a_rows, ca.fortran_vec (), |
|
130 cb.fortran_vec (), &eps, &matz, |
|
131 jnk.fortran_vec (), &info); |
|
132 |
|
133 if (info) |
|
134 error ("qzvalue: trouble in qzit, info = %d", info); |
|
135 |
|
136 F77_FCN (qzval) (&a_rows, &a_rows, ca.fortran_vec (), |
|
137 cb.fortran_vec (), alfr.fortran_vec (), |
|
138 alfi.fortran_vec (), beta.fortran_vec (), |
|
139 &matz, jnk.fortran_vec ()); |
|
140 |
|
141 // Count and extract finite generalized eigenvalues. |
|
142 |
|
143 int i, cnt; |
|
144 Complex Im (0, 1); |
|
145 for (i = 0, cnt = 0; i < a_rows; i++) |
|
146 if (beta (i) != 0) |
|
147 cnt++; |
|
148 |
|
149 ComplexColumnVector cx (cnt, 0.0); |
|
150 |
|
151 for (i = 0; i < a_rows; i++) |
|
152 { |
|
153 if (beta (i) != 0) |
|
154 { |
|
155 |
|
156 // Finite generalized eigenvalue. |
|
157 |
|
158 cnt--; |
|
159 cx (cnt) = (alfr (i) + Im * alfi (i)) / beta (i); |
|
160 } |
|
161 } |
516
|
162 retval(0) = cx; |
44
|
163 } |
|
164 } |
|
165 return retval; |
|
166 } |
|
167 |
|
168 /* |
|
169 ;;; Local Variables: *** |
|
170 ;;; mode: C++ *** |
|
171 ;;; page-delimiter: "^/\\*" *** |
|
172 ;;; End: *** |
|
173 */ |