2928
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1999, 2000, 2004, 2005, 2006, 2007 |
|
4 John W. Eaton |
2928
|
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 |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2928
|
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 |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2928
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "CmplxHESS.h" |
|
29 #include "dbleHESS.h" |
|
30 |
|
31 #include "defun-dld.h" |
|
32 #include "error.h" |
|
33 #include "gripes.h" |
|
34 #include "oct-obj.h" |
|
35 #include "utils.h" |
|
36 |
|
37 DEFUN_DLD (hess, args, nargout, |
3548
|
38 "-*- texinfo -*-\n\ |
3372
|
39 @deftypefn {Loadable Function} {@var{h} =} hess (@var{a})\n\ |
|
40 @deftypefnx {Loadable Function} {[@var{p}, @var{h}] =} hess (@var{a})\n\ |
|
41 @cindex Hessenberg decomposition\n\ |
|
42 Compute the Hessenberg decomposition of the matrix @var{a}.\n\ |
|
43 \n\ |
|
44 The Hessenberg decomposition is usually used as the first step in an\n\ |
|
45 eigenvalue computation, but has other applications as well (see Golub,\n\ |
4684
|
46 Nash, and Van Loan, IEEE Transactions on Automatic Control, 1979). The\n\ |
3372
|
47 Hessenberg decomposition is\n\ |
|
48 @iftex\n\ |
|
49 @tex\n\ |
|
50 $$\n\ |
|
51 A = PHP^T\n\ |
|
52 $$\n\ |
|
53 where $P$ is a square unitary matrix ($P^HP = I$), and $H$\n\ |
|
54 is upper Hessenberg ($H_{i,j} = 0, \\forall i \\ge j+1$).\n\ |
|
55 @end tex\n\ |
|
56 @end iftex\n\ |
|
57 @ifinfo\n\ |
|
58 @code{p * h * p' = a} where @code{p} is a square unitary matrix\n\ |
|
59 (@code{p' * p = I}, using complex-conjugate transposition) and @code{h}\n\ |
|
60 is upper Hessenberg (@code{i >= j+1 => h (i, j) = 0}).\n\ |
|
61 @end ifinfo\n\ |
|
62 @end deftypefn") |
2928
|
63 { |
|
64 octave_value_list retval; |
|
65 |
|
66 int nargin = args.length (); |
|
67 |
|
68 if (nargin != 1 || nargout > 2) |
|
69 { |
5823
|
70 print_usage (); |
2928
|
71 return retval; |
|
72 } |
|
73 |
|
74 octave_value arg = args(0); |
|
75 |
5275
|
76 octave_idx_type nr = arg.rows (); |
|
77 octave_idx_type nc = arg.columns (); |
2928
|
78 |
|
79 int arg_is_empty = empty_arg ("hess", nr, nc); |
|
80 |
|
81 if (arg_is_empty < 0) |
|
82 return retval; |
|
83 else if (arg_is_empty > 0) |
|
84 return octave_value_list (2, Matrix ()); |
|
85 |
|
86 if (nr != nc) |
|
87 { |
|
88 gripe_square_matrix_required ("hess"); |
|
89 return retval; |
|
90 } |
|
91 |
|
92 if (arg.is_real_type ()) |
|
93 { |
|
94 Matrix tmp = arg.matrix_value (); |
|
95 |
|
96 if (! error_state) |
|
97 { |
|
98 HESS result (tmp); |
|
99 |
|
100 if (nargout == 0 || nargout == 1) |
|
101 { |
|
102 retval.resize (1); |
|
103 retval(0) = result.hess_matrix (); |
|
104 } |
|
105 else |
|
106 { |
|
107 retval.resize (2); |
|
108 retval(0) = result.unitary_hess_matrix (); |
|
109 retval(1) = result.hess_matrix (); |
|
110 } |
|
111 } |
|
112 } |
|
113 else if (arg.is_complex_type ()) |
|
114 { |
|
115 ComplexMatrix ctmp = arg.complex_matrix_value (); |
|
116 |
|
117 if (! error_state) |
|
118 { |
|
119 ComplexHESS result (ctmp); |
|
120 |
|
121 if (nargout == 0 || nargout == 1) |
|
122 { |
|
123 retval.resize (1); |
|
124 retval(0) = result.hess_matrix (); |
|
125 } |
|
126 else |
|
127 { |
|
128 retval.resize (2); |
|
129 retval(0) = result.unitary_hess_matrix (); |
|
130 retval(1) = result.hess_matrix (); |
|
131 } |
|
132 } |
|
133 } |
|
134 else |
|
135 { |
|
136 gripe_wrong_type_arg ("hess", arg); |
|
137 } |
|
138 |
|
139 return retval; |
|
140 } |
|
141 |
|
142 /* |
|
143 ;;; Local Variables: *** |
|
144 ;;; mode: C++ *** |
|
145 ;;; End: *** |
|
146 */ |