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" |
1368
|
36 #include "mx-inlines.cc" |
457
|
37 |
|
38 extern "C" |
|
39 { |
1253
|
40 int F77_FCN (dgeesx, DGEESX) (const char*, const char*, |
1929
|
41 SCHUR::select_function, const char*, |
|
42 const int&, double*, const int&, |
|
43 int&, double*, double*, double*, |
|
44 const int&, double&, double&, double*, |
|
45 const int&, int*, const int&, int*, |
|
46 int&, long, long); |
457
|
47 } |
|
48 |
|
49 static int |
1486
|
50 select_ana (const double& a, const double&) |
457
|
51 { |
1251
|
52 return (a < 0.0); |
457
|
53 } |
|
54 |
|
55 static int |
1251
|
56 select_dig (const double& a, const double& b) |
457
|
57 { |
1251
|
58 return (hypot (a, b) < 1.0); |
457
|
59 } |
|
60 |
|
61 int |
1756
|
62 SCHUR::init (const Matrix& a, const string& ord) |
457
|
63 { |
|
64 int a_nr = a.rows (); |
|
65 int a_nc = a.cols (); |
1929
|
66 |
457
|
67 if (a_nr != a_nc) |
|
68 { |
|
69 (*current_liboctave_error_handler) ("SCHUR requires square matrix"); |
|
70 return -1; |
|
71 } |
|
72 |
1930
|
73 char jobvs = 'V'; |
|
74 char sense = 'N'; |
|
75 char sort = 'N'; |
457
|
76 |
1756
|
77 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
78 |
|
79 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1930
|
80 sort = 'S'; |
457
|
81 |
1929
|
82 if (ord_char == 'A' || ord_char == 'a') |
|
83 selector = select_ana; |
|
84 else if (ord_char == 'D' || ord_char == 'd') |
|
85 selector = select_dig; |
1930
|
86 else |
|
87 selector = 0; |
457
|
88 |
|
89 int n = a_nc; |
|
90 int lwork = 8 * n; |
|
91 int liwork = 1; |
|
92 int info; |
|
93 int sdim; |
|
94 double rconde; |
|
95 double rcondv; |
|
96 |
1929
|
97 schur_mat = a; |
|
98 unitary_mat.resize (n, n); |
|
99 |
|
100 double *s = schur_mat.fortran_vec (); |
|
101 double *q = unitary_mat.fortran_vec (); |
457
|
102 |
1929
|
103 Array<double> wr (n); |
|
104 double *pwr = wr.fortran_vec (); |
|
105 |
|
106 Array<double> wi (n); |
|
107 double *pwi = wi.fortran_vec (); |
|
108 |
|
109 Array<double> work (lwork); |
|
110 double *pwork = work.fortran_vec (); |
457
|
111 |
1360
|
112 // These are not referenced for the non-ordered Schur routine. |
457
|
113 |
1929
|
114 Array<int> bwork; |
|
115 Array<int> iwork; |
|
116 |
1756
|
117 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
457
|
118 { |
1929
|
119 bwork.resize (n); |
|
120 iwork.resize (liwork); |
457
|
121 } |
|
122 |
1929
|
123 int *pbwork = bwork.fortran_vec (); |
|
124 int *piwork = iwork.fortran_vec (); |
|
125 |
457
|
126 |
1930
|
127 F77_XFCN (dgeesx, DGEESX, (&jobvs, &sort, selector, &sense, n, s, |
1929
|
128 n, sdim, pwr, pwi, q, n, rconde, rcondv, |
|
129 pwork, lwork, piwork, liwork, pbwork, |
|
130 info, 1L, 1L)); |
457
|
131 |
1929
|
132 if (f77_exception_encountered) |
|
133 (*current_liboctave_error_handler) ("unrecoverable error in dgeesx"); |
457
|
134 |
|
135 return info; |
|
136 } |
|
137 |
|
138 ostream& |
|
139 operator << (ostream& os, const SCHUR& a) |
|
140 { |
|
141 os << a.schur_matrix () << "\n"; |
|
142 os << a.unitary_matrix () << "\n"; |
|
143 |
|
144 return os; |
|
145 } |
|
146 |
|
147 /* |
|
148 ;;; Local Variables: *** |
|
149 ;;; mode: C++ *** |
|
150 ;;; End: *** |
|
151 */ |