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