457
|
1 /* |
|
2 |
1882
|
3 Copyright (C) 1996 John W. Eaton |
457
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
457
|
20 |
|
21 */ |
|
22 |
1296
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
457
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
457
|
29 #endif |
|
30 |
1631
|
31 #include <iostream.h> |
|
32 |
457
|
33 #include "dbleSCHUR.h" |
1847
|
34 #include "f77-fcn.h" |
457
|
35 #include "lo-error.h" |
|
36 |
|
37 extern "C" |
|
38 { |
1253
|
39 int F77_FCN (dgeesx, DGEESX) (const char*, const char*, |
1929
|
40 SCHUR::select_function, const char*, |
|
41 const int&, double*, const int&, |
|
42 int&, double*, double*, double*, |
|
43 const int&, double&, double&, double*, |
|
44 const int&, int*, const int&, int*, |
|
45 int&, long, long); |
457
|
46 } |
|
47 |
|
48 static int |
1486
|
49 select_ana (const double& a, const double&) |
457
|
50 { |
1251
|
51 return (a < 0.0); |
457
|
52 } |
|
53 |
|
54 static int |
1251
|
55 select_dig (const double& a, const double& b) |
457
|
56 { |
1251
|
57 return (hypot (a, b) < 1.0); |
457
|
58 } |
|
59 |
|
60 int |
1756
|
61 SCHUR::init (const Matrix& a, const string& ord) |
457
|
62 { |
|
63 int a_nr = a.rows (); |
|
64 int a_nc = a.cols (); |
1929
|
65 |
457
|
66 if (a_nr != a_nc) |
|
67 { |
|
68 (*current_liboctave_error_handler) ("SCHUR requires square matrix"); |
|
69 return -1; |
|
70 } |
|
71 |
1930
|
72 char jobvs = 'V'; |
|
73 char sense = 'N'; |
|
74 char sort = 'N'; |
457
|
75 |
1756
|
76 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
77 |
|
78 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1930
|
79 sort = 'S'; |
457
|
80 |
1929
|
81 if (ord_char == 'A' || ord_char == 'a') |
|
82 selector = select_ana; |
|
83 else if (ord_char == 'D' || ord_char == 'd') |
|
84 selector = select_dig; |
1930
|
85 else |
|
86 selector = 0; |
457
|
87 |
|
88 int n = a_nc; |
|
89 int lwork = 8 * n; |
|
90 int liwork = 1; |
|
91 int info; |
|
92 int sdim; |
|
93 double rconde; |
|
94 double rcondv; |
|
95 |
1929
|
96 schur_mat = a; |
|
97 unitary_mat.resize (n, n); |
|
98 |
|
99 double *s = schur_mat.fortran_vec (); |
|
100 double *q = unitary_mat.fortran_vec (); |
457
|
101 |
1929
|
102 Array<double> wr (n); |
|
103 double *pwr = wr.fortran_vec (); |
|
104 |
|
105 Array<double> wi (n); |
|
106 double *pwi = wi.fortran_vec (); |
|
107 |
|
108 Array<double> work (lwork); |
|
109 double *pwork = work.fortran_vec (); |
457
|
110 |
1360
|
111 // These are not referenced for the non-ordered Schur routine. |
457
|
112 |
1929
|
113 Array<int> bwork; |
|
114 Array<int> iwork; |
|
115 |
1756
|
116 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
457
|
117 { |
1929
|
118 bwork.resize (n); |
|
119 iwork.resize (liwork); |
457
|
120 } |
|
121 |
1929
|
122 int *pbwork = bwork.fortran_vec (); |
|
123 int *piwork = iwork.fortran_vec (); |
|
124 |
457
|
125 |
1930
|
126 F77_XFCN (dgeesx, DGEESX, (&jobvs, &sort, selector, &sense, n, s, |
1929
|
127 n, sdim, pwr, pwi, q, n, rconde, rcondv, |
|
128 pwork, lwork, piwork, liwork, pbwork, |
|
129 info, 1L, 1L)); |
457
|
130 |
1929
|
131 if (f77_exception_encountered) |
|
132 (*current_liboctave_error_handler) ("unrecoverable error in dgeesx"); |
457
|
133 |
|
134 return info; |
|
135 } |
|
136 |
|
137 ostream& |
|
138 operator << (ostream& os, const SCHUR& a) |
|
139 { |
|
140 os << a.schur_matrix () << "\n"; |
|
141 os << a.unitary_matrix () << "\n"; |
|
142 |
|
143 return os; |
|
144 } |
|
145 |
|
146 /* |
|
147 ;;; Local Variables: *** |
|
148 ;;; mode: C++ *** |
|
149 ;;; End: *** |
|
150 */ |