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