7017
|
1 ## Copyright (C) 1993, 1995, 1996, 1997, 1999, 2000, 2005, 2006, 2007 |
|
2 ## John W. Eaton |
2313
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
2313
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
245
|
19 |
3372
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {[@var{aa}, @var{bb}, @var{q}, @var{z}] =} qzhess (@var{a}, @var{b}) |
|
22 ## Compute the Hessenberg-triangular decomposition of the matrix pencil |
|
23 ## @code{(@var{a}, @var{b})}, returning |
3426
|
24 ## @code{@var{aa} = @var{q} * @var{a} * @var{z}}, |
3372
|
25 ## @code{@var{bb} = @var{q} * @var{b} * @var{z}}, with @var{q} and @var{z} |
|
26 ## orthogonal. For example, |
3426
|
27 ## |
3372
|
28 ## @example |
|
29 ## @group |
|
30 ## [aa, bb, q, z] = qzhess ([1, 2; 3, 4], [5, 6; 7, 8]) |
|
31 ## @result{} aa = [ -3.02244, -4.41741; 0.92998, 0.69749 ] |
|
32 ## @result{} bb = [ -8.60233, -9.99730; 0.00000, -0.23250 ] |
|
33 ## @result{} q = [ -0.58124, -0.81373; -0.81373, 0.58124 ] |
|
34 ## @result{} z = [ 1, 0; 0, 1 ] |
|
35 ## @end group |
|
36 ## @end example |
3426
|
37 ## |
3372
|
38 ## The Hessenberg-triangular decomposition is the first step in |
|
39 ## Moler and Stewart's QZ decomposition algorithm. |
3426
|
40 ## |
3372
|
41 ## Algorithm taken from Golub and Van Loan, @cite{Matrix Computations, 2nd |
|
42 ## edition}. |
|
43 ## @end deftypefn |
29
|
44 |
2312
|
45 ## Author: A. S. Hodel <scotte@eng.auburn.edu> |
|
46 ## Created: August 1993 |
|
47 ## Adapted-By: jwe |
29
|
48 |
2312
|
49 function [aa, bb, q, z] = qzhess (a, b) |
72
|
50 |
54
|
51 if (nargin != 2) |
6046
|
52 print_usage (); |
54
|
53 endif |
|
54 |
|
55 [na, ma] = size (a); |
|
56 [nb, mb] = size (b); |
|
57 if (na != ma || na != nb || nb != mb) |
|
58 error ("qzhess: incompatible dimensions"); |
|
59 endif |
|
60 |
2303
|
61 ## Reduce to hessenberg-triangular form. |
29
|
62 |
54
|
63 [q, bb] = qr (b); |
|
64 aa = q' * a; |
|
65 q = q'; |
|
66 z = eye (na); |
|
67 for j = 1:(na-2) |
|
68 for i = na:-1:(j+2) |
|
69 |
2303
|
70 ## disp (["zero out aa(", num2str(i), ",", num2str(j), ")"]) |
54
|
71 |
|
72 rot = givens (aa (i-1, j), aa (i, j)); |
|
73 aa ((i-1):i, :) = rot *aa ((i-1):i, :); |
|
74 bb ((i-1):i, :) = rot *bb ((i-1):i, :); |
|
75 q ((i-1):i, :) = rot *q ((i-1):i, :); |
|
76 |
2303
|
77 ## disp (["now zero out bb(", num2str(i), ",", num2str(i-1), ")"]) |
54
|
78 |
|
79 rot = givens (bb (i, i), bb (i, i-1))'; |
|
80 bb (:, (i-1):i) = bb (:, (i-1):i) * rot'; |
|
81 aa (:, (i-1):i) = aa (:, (i-1):i) * rot'; |
|
82 z (:, (i-1):i) = z (:, (i-1):i) * rot'; |
|
83 |
|
84 endfor |
29
|
85 endfor |
|
86 |
54
|
87 bb (2, 1) = 0.0; |
|
88 for i = 3:na |
|
89 bb (i, 1:(i-1)) = zeros (1, i-1); |
|
90 aa (i, 1:(i-2)) = zeros (1, i-2); |
|
91 endfor |
|
92 |
29
|
93 endfunction |