1
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 John W. Eaton |
1
|
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. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
1352
|
27 #include "CmplxHESS.h" |
453
|
28 #include "dbleHESS.h" |
1
|
29 |
1352
|
30 #include "defun-dld.h" |
|
31 #include "error.h" |
|
32 #include "gripes.h" |
|
33 #include "help.h" |
1740
|
34 #include "oct-obj.h" |
1
|
35 #include "user-prefs.h" |
636
|
36 #include "utils.h" |
1
|
37 |
1957
|
38 DEFUN_DLD_BUILTIN (hess, args, nargout, |
519
|
39 "[P, H] = hess (A) or H = hess (A): Hessenberg decomposition") |
1
|
40 { |
2086
|
41 octave_value_list retval; |
1
|
42 |
712
|
43 int nargin = args.length (); |
|
44 |
|
45 if (nargin != 1 || nargout > 2) |
519
|
46 { |
|
47 print_usage ("hess"); |
|
48 return retval; |
|
49 } |
|
50 |
2086
|
51 octave_value arg = args(0); |
1
|
52 |
636
|
53 int nr = arg.rows (); |
|
54 int nc = arg.columns (); |
1
|
55 |
718
|
56 int arg_is_empty = empty_arg ("hess", nr, nc); |
|
57 |
|
58 if (arg_is_empty < 0) |
636
|
59 return retval; |
718
|
60 else if (arg_is_empty > 0) |
2086
|
61 return octave_value_list (2, Matrix ()); |
1
|
62 |
636
|
63 if (nr != nc) |
1
|
64 { |
|
65 gripe_square_matrix_required ("hess"); |
|
66 return retval; |
|
67 } |
|
68 |
636
|
69 if (arg.is_real_type ()) |
|
70 { |
|
71 Matrix tmp = arg.matrix_value (); |
1
|
72 |
636
|
73 if (! error_state) |
|
74 { |
|
75 HESS result (tmp); |
1
|
76 |
636
|
77 if (nargout == 0 || nargout == 1) |
|
78 { |
|
79 retval.resize (1); |
|
80 retval(0) = result.hess_matrix (); |
|
81 } |
|
82 else |
|
83 { |
|
84 retval.resize (2); |
|
85 retval(0) = result.unitary_hess_matrix (); |
|
86 retval(1) = result.hess_matrix (); |
|
87 } |
620
|
88 } |
|
89 } |
636
|
90 else if (arg.is_complex_type ()) |
620
|
91 { |
636
|
92 ComplexMatrix ctmp = arg.complex_matrix_value (); |
1
|
93 |
636
|
94 if (! error_state) |
620
|
95 { |
636
|
96 ComplexHESS result (ctmp); |
|
97 |
|
98 if (nargout == 0 || nargout == 1) |
|
99 { |
|
100 retval.resize (1); |
|
101 retval(0) = result.hess_matrix (); |
|
102 } |
|
103 else |
|
104 { |
|
105 retval.resize (2); |
|
106 retval(0) = result.unitary_hess_matrix (); |
|
107 retval(1) = result.hess_matrix (); |
|
108 } |
620
|
109 } |
|
110 } |
|
111 else |
|
112 { |
|
113 gripe_wrong_type_arg ("hess", arg); |
|
114 } |
|
115 |
1
|
116 return retval; |
|
117 } |
|
118 |
|
119 /* |
|
120 ;;; Local Variables: *** |
|
121 ;;; mode: C++ *** |
|
122 ;;; End: *** |
|
123 */ |