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