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