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