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