7
|
1 // f-hess.cc -*- C++ -*- |
1
|
2 /* |
|
3 |
453
|
4 Copyright (C) 1993, 1994 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 |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
453
|
28 #include "dbleHESS.h" |
|
29 #include "CmplxHESS.h" |
1
|
30 |
|
31 #include "tree-const.h" |
|
32 #include "user-prefs.h" |
|
33 #include "error.h" |
|
34 #include "gripes.h" |
636
|
35 #include "utils.h" |
544
|
36 #include "help.h" |
519
|
37 #include "defun-dld.h" |
1
|
38 |
701
|
39 DEFUN_DLD_BUILTIN ("hess", Fhess, Shess, 2, 2, |
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 |
636
|
57 if (empty_arg ("hess", nr, nc) < 0) |
|
58 return retval; |
1
|
59 |
636
|
60 if (nr != nc) |
1
|
61 { |
|
62 gripe_square_matrix_required ("hess"); |
|
63 return retval; |
|
64 } |
|
65 |
636
|
66 if (arg.is_real_type ()) |
|
67 { |
|
68 Matrix tmp = arg.matrix_value (); |
1
|
69 |
636
|
70 if (! error_state) |
|
71 { |
|
72 HESS result (tmp); |
1
|
73 |
636
|
74 if (nargout == 0 || nargout == 1) |
|
75 { |
|
76 retval.resize (1); |
|
77 retval(0) = result.hess_matrix (); |
|
78 } |
|
79 else |
|
80 { |
|
81 retval.resize (2); |
|
82 retval(0) = result.unitary_hess_matrix (); |
|
83 retval(1) = result.hess_matrix (); |
|
84 } |
620
|
85 } |
|
86 } |
636
|
87 else if (arg.is_complex_type ()) |
620
|
88 { |
636
|
89 ComplexMatrix ctmp = arg.complex_matrix_value (); |
1
|
90 |
636
|
91 if (! error_state) |
620
|
92 { |
636
|
93 ComplexHESS result (ctmp); |
|
94 |
|
95 if (nargout == 0 || nargout == 1) |
|
96 { |
|
97 retval.resize (1); |
|
98 retval(0) = result.hess_matrix (); |
|
99 } |
|
100 else |
|
101 { |
|
102 retval.resize (2); |
|
103 retval(0) = result.unitary_hess_matrix (); |
|
104 retval(1) = result.hess_matrix (); |
|
105 } |
620
|
106 } |
|
107 } |
|
108 else |
|
109 { |
|
110 gripe_wrong_type_arg ("hess", arg); |
|
111 } |
|
112 |
1
|
113 return retval; |
|
114 } |
|
115 |
|
116 /* |
|
117 ;;; Local Variables: *** |
|
118 ;;; mode: C++ *** |
|
119 ;;; page-delimiter: "^/\\*" *** |
|
120 ;;; End: *** |
|
121 */ |