2303
|
1 ### Copyright (C) 1996 John W. Eaton |
|
2 ### |
|
3 ### This file is part of Octave. |
|
4 ### |
|
5 ### Octave is free software; you can redistribute it and/or modify it |
|
6 ### under the terms of the GNU General Public License as published by |
|
7 ### the Free Software Foundation; either version 2, or (at your option) |
|
8 ### any later version. |
|
9 ### |
|
10 ### Octave is distributed in the hope that it will be useful, but |
|
11 ### WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ### General Public License for more details. |
|
14 ### |
|
15 ### You should have received a copy of the GNU General Public License |
|
16 ### along with Octave; see the file COPYING. If not, write to the Free |
|
17 ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ### 02111-1307, USA. |
245
|
19 |
54
|
20 function [aa, bb, q, z] = qzhess (a, b) |
29
|
21 |
2303
|
22 ## Usage: [aa, bb, q, z] = qzhess (a, b) |
|
23 ## |
|
24 ## Compute the qz decomposition of the matrix pencil (a - lambda b) |
|
25 ## |
|
26 ## result: (for Matlab compatibility): |
|
27 ## |
|
28 ## aa = q*a*z and bb = q*b*z, with q, z orthogonal, and |
|
29 ## v = matrix of generalized eigenvectors. |
|
30 ## |
|
31 ## This ought to be done in a compiled program |
|
32 ## |
|
33 ## Algorithm taken from Golub and Van Loan, Matrix Computations, 2nd ed. |
29
|
34 |
2303
|
35 ## Written by A. S. Hodel (scotte@eng.auburn.edu) August 1993. |
72
|
36 |
54
|
37 if (nargin != 2) |
|
38 error ("usage: [aa, bb, q, z] = qzhess (a, b)"); |
|
39 endif |
|
40 |
|
41 [na, ma] = size (a); |
|
42 [nb, mb] = size (b); |
|
43 if (na != ma || na != nb || nb != mb) |
|
44 error ("qzhess: incompatible dimensions"); |
|
45 endif |
|
46 |
2303
|
47 ## Reduce to hessenberg-triangular form. |
29
|
48 |
54
|
49 [q, bb] = qr (b); |
|
50 aa = q' * a; |
|
51 q = q'; |
|
52 z = eye (na); |
|
53 for j = 1:(na-2) |
|
54 for i = na:-1:(j+2) |
|
55 |
2303
|
56 ## disp (["zero out aa(", num2str(i), ",", num2str(j), ")"]) |
54
|
57 |
|
58 rot = givens (aa (i-1, j), aa (i, j)); |
|
59 aa ((i-1):i, :) = rot *aa ((i-1):i, :); |
|
60 bb ((i-1):i, :) = rot *bb ((i-1):i, :); |
|
61 q ((i-1):i, :) = rot *q ((i-1):i, :); |
|
62 |
2303
|
63 ## disp (["now zero out bb(", num2str(i), ",", num2str(i-1), ")"]) |
54
|
64 |
|
65 rot = givens (bb (i, i), bb (i, i-1))'; |
|
66 bb (:, (i-1):i) = bb (:, (i-1):i) * rot'; |
|
67 aa (:, (i-1):i) = aa (:, (i-1):i) * rot'; |
|
68 z (:, (i-1):i) = z (:, (i-1):i) * rot'; |
|
69 |
|
70 endfor |
29
|
71 endfor |
|
72 |
54
|
73 bb (2, 1) = 0.0; |
|
74 for i = 3:na |
|
75 bb (i, 1:(i-1)) = zeros (1, i-1); |
|
76 aa (i, 1:(i-2)) = zeros (1, i-2); |
|
77 endfor |
|
78 |
29
|
79 endfunction |