7
|
1 // f-schur.cc -*- C++ -*- |
1
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1993, 1994, 1995 John W. Eaton |
1
|
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 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1
|
26 #endif |
|
27 |
453
|
28 #include "dbleSCHUR.h" |
|
29 #include "CmplxSCHUR.h" |
1
|
30 |
|
31 #include "tree-const.h" |
|
32 #include "user-prefs.h" |
636
|
33 #include "utils.h" |
1
|
34 #include "error.h" |
|
35 #include "gripes.h" |
544
|
36 #include "help.h" |
519
|
37 #include "defun-dld.h" |
1
|
38 |
701
|
39 DEFUN_DLD_BUILTIN ("schur", Fschur, Sschur, 3, 2, |
519
|
40 "[U, S] = schur (A) or S = schur (A)\n\ |
|
41 \n\ |
|
42 or, for ordered Schur:\n\ |
|
43 \n\ |
|
44 [U, S] = schur (A, TYPE) or S = schur (A, TYPE)\n\ |
|
45 where TYPE is a string that begins with one of the following\n\ |
|
46 characters:\n\ |
|
47 \n\ |
|
48 A = continuous time poles\n\ |
|
49 D = discrete time poles\n\ |
|
50 U = unordered schur (default)") |
1
|
51 { |
497
|
52 Octave_object retval; |
1
|
53 |
506
|
54 int nargin = args.length (); |
|
55 |
712
|
56 if (nargin < 1 || nargin > 2 || nargout > 2) |
519
|
57 { |
|
58 print_usage ("schur"); |
|
59 return retval; |
|
60 } |
|
61 |
712
|
62 tree_constant arg = args(0); |
636
|
63 |
|
64 char *ord = "U"; |
712
|
65 if (nargin == 2) |
636
|
66 { |
712
|
67 ord = args(1).string_value (); |
1
|
68 |
636
|
69 if (error_state) |
|
70 { |
666
|
71 error ("schur: expecting string as second argument"); |
636
|
72 return retval; |
|
73 } |
|
74 } |
1
|
75 |
|
76 if (*ord != 'U' && *ord != 'A' && *ord != 'D' |
|
77 && *ord != 'u' && *ord != 'a' && *ord != 'd') |
|
78 { |
|
79 warning ("schur: incorrect ordered schur argument `%c'", *ord); |
|
80 return retval; |
|
81 } |
636
|
82 |
|
83 int nr = arg.rows (); |
|
84 int nc = arg.columns (); |
1
|
85 |
718
|
86 int arg_is_empty = empty_arg ("schur", nr, nc); |
|
87 |
|
88 if (arg_is_empty < 0) |
636
|
89 return retval; |
718
|
90 else if (arg_is_empty > 0) |
|
91 return Octave_object (2, Matrix ()); |
1
|
92 |
636
|
93 if (nr != nc) |
1
|
94 { |
|
95 gripe_square_matrix_required ("schur"); |
|
96 return retval; |
|
97 } |
|
98 |
785
|
99 if (arg.is_real_type ()) |
1
|
100 { |
636
|
101 Matrix tmp = arg.matrix_value (); |
1
|
102 |
636
|
103 if (! error_state) |
620
|
104 { |
636
|
105 SCHUR result (tmp,ord); |
|
106 |
|
107 if (nargout == 0 || nargout == 1) |
|
108 { |
|
109 retval(0) = result.schur_matrix (); |
|
110 } |
|
111 else |
|
112 { |
|
113 retval(1) = result.schur_matrix (); |
|
114 retval(0) = result.unitary_matrix (); |
|
115 } |
620
|
116 } |
|
117 } |
785
|
118 else if (arg.is_complex_type ()) |
620
|
119 { |
636
|
120 ComplexMatrix ctmp = arg.complex_matrix_value (); |
1
|
121 |
636
|
122 if (! error_state) |
620
|
123 { |
636
|
124 ComplexSCHUR result (ctmp,ord); |
|
125 |
|
126 if (nargout == 0 || nargout == 1) |
|
127 { |
|
128 retval(0) = result.schur_matrix (); |
|
129 } |
|
130 else |
|
131 { |
|
132 retval(1) = result.schur_matrix (); |
|
133 retval(0) = result.unitary_matrix (); |
|
134 } |
620
|
135 } |
|
136 } |
|
137 else |
|
138 { |
|
139 gripe_wrong_type_arg ("schur", arg); |
1
|
140 } |
|
141 |
|
142 return retval; |
|
143 } |
|
144 |
|
145 /* |
|
146 ;;; Local Variables: *** |
|
147 ;;; mode: C++ *** |
|
148 ;;; page-delimiter: "^/\\*" *** |
|
149 ;;; End: *** |
|
150 */ |