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