2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 // Written by A. S. Hodel <scotte@eng.auburn.edu> |
|
24 |
|
25 #ifdef HAVE_CONFIG_H |
|
26 #include <config.h> |
|
27 #endif |
|
28 |
|
29 #include "defun-dld.h" |
|
30 #include "error.h" |
|
31 #include "gripes.h" |
|
32 #include "help.h" |
|
33 #include "oct-obj.h" |
|
34 #include "utils.h" |
|
35 |
|
36 DEFUN_DLD (syl, args, nargout, |
|
37 "X = syl (A, B, C): solve the Sylvester equation A X + X B + C = 0") |
|
38 { |
|
39 octave_value_list retval; |
|
40 |
|
41 int nargin = args.length (); |
|
42 |
|
43 if (nargin != 3 || nargout > 1) |
|
44 { |
|
45 print_usage ("syl"); |
|
46 return retval; |
|
47 } |
|
48 |
|
49 octave_value arg_a = args(0); |
|
50 octave_value arg_b = args(1); |
|
51 octave_value arg_c = args(2); |
|
52 |
|
53 int a_nr = arg_a.rows (); |
|
54 int a_nc = arg_a.columns (); |
|
55 |
|
56 int b_nr = arg_b.rows (); |
|
57 int b_nc = arg_b.columns (); |
|
58 |
|
59 int c_nr = arg_c.rows (); |
|
60 int c_nc = arg_c.columns (); |
|
61 |
|
62 int arg_a_is_empty = empty_arg ("syl", a_nr, a_nc); |
|
63 int arg_b_is_empty = empty_arg ("syl", b_nr, b_nc); |
|
64 int arg_c_is_empty = empty_arg ("syl", c_nr, c_nc); |
|
65 |
|
66 if (arg_a_is_empty > 0 && arg_b_is_empty > 0 && arg_c_is_empty > 0) |
|
67 return Matrix (); |
|
68 else if (arg_a_is_empty || arg_b_is_empty || arg_c_is_empty) |
|
69 return retval; |
|
70 |
|
71 // Arguments are not empty, so check for correct dimensions. |
|
72 |
|
73 if (a_nr != a_nc || b_nr != b_nc) |
|
74 { |
|
75 gripe_square_matrix_required ("syl: first two parameters:"); |
|
76 return retval; |
|
77 } |
|
78 else if (a_nr != c_nr || b_nr != c_nc) |
|
79 { |
|
80 gripe_nonconformant (); |
|
81 return retval; |
|
82 } |
|
83 |
|
84 // Dimensions look o.k., let's solve the problem. |
|
85 |
|
86 if (arg_a.is_complex_type () |
|
87 || arg_b.is_complex_type () |
|
88 || arg_c.is_complex_type ()) |
|
89 { |
|
90 // Do everything in complex arithmetic; |
|
91 |
|
92 ComplexMatrix ca = arg_a.complex_matrix_value (); |
|
93 |
|
94 if (error_state) |
|
95 return retval; |
|
96 |
|
97 ComplexMatrix cb = arg_b.complex_matrix_value (); |
|
98 |
|
99 if (error_state) |
|
100 return retval; |
|
101 |
|
102 ComplexMatrix cc = arg_c.complex_matrix_value (); |
|
103 |
|
104 if (error_state) |
|
105 return retval; |
|
106 |
|
107 retval = Sylvester (ca, cb, cc); |
|
108 } |
|
109 else |
|
110 { |
|
111 // Do everything in real arithmetic. |
|
112 |
|
113 Matrix ca = arg_a.matrix_value (); |
|
114 |
|
115 if (error_state) |
|
116 return retval; |
|
117 |
|
118 Matrix cb = arg_b.matrix_value (); |
|
119 |
|
120 if (error_state) |
|
121 return retval; |
|
122 |
|
123 Matrix cc = arg_c.matrix_value (); |
|
124 |
|
125 if (error_state) |
|
126 return retval; |
|
127 |
|
128 retval = Sylvester (ca, cb, cc); |
|
129 } |
|
130 |
|
131 return retval; |
|
132 } |
|
133 |
|
134 /* |
|
135 ;;; Local Variables: *** |
|
136 ;;; mode: C++ *** |
|
137 ;;; End: *** |
|
138 */ |