54
|
1 function [aa, bb, q, z] = qzhess (a, b) |
29
|
2 |
72
|
3 # Usage: [aa, bb, q, z] = qzhess (a, b) |
|
4 # |
54
|
5 # Compute the qz decomposition of the matrix pencil (a - lambda b) |
|
6 # |
|
7 # result: (for Matlab compatibility): |
|
8 # |
|
9 # aa = q*a*z and bb = q*b*z, with q, z orthogonal, and |
|
10 # v = matrix of generalized eigenvectors. |
|
11 # |
|
12 # This ought to be done in a compiled program |
|
13 # |
|
14 # Algorithm taken from Golub and Van Loan, Matrix Computations, 2nd ed. |
29
|
15 |
72
|
16 # Written by A. S. Hodel (scotte@eng.auburn.edu) August 1993. |
|
17 |
54
|
18 if (nargin != 2) |
|
19 error ("usage: [aa, bb, q, z] = qzhess (a, b)"); |
|
20 endif |
|
21 |
|
22 [na, ma] = size (a); |
|
23 [nb, mb] = size (b); |
|
24 if (na != ma || na != nb || nb != mb) |
|
25 error ("qzhess: incompatible dimensions"); |
|
26 endif |
|
27 |
|
28 # Reduce to hessenberg-triangular form. |
29
|
29 |
54
|
30 [q, bb] = qr (b); |
|
31 aa = q' * a; |
|
32 q = q'; |
|
33 z = eye (na); |
|
34 for j = 1:(na-2) |
|
35 for i = na:-1:(j+2) |
|
36 |
|
37 # disp (["zero out aa(", num2str(i), ",", num2str(j), ")"]) |
|
38 |
|
39 rot = givens (aa (i-1, j), aa (i, j)); |
|
40 aa ((i-1):i, :) = rot *aa ((i-1):i, :); |
|
41 bb ((i-1):i, :) = rot *bb ((i-1):i, :); |
|
42 q ((i-1):i, :) = rot *q ((i-1):i, :); |
|
43 |
|
44 # disp (["now zero out bb(", num2str(i), ",", num2str(i-1), ")"]) |
|
45 |
|
46 rot = givens (bb (i, i), bb (i, i-1))'; |
|
47 bb (:, (i-1):i) = bb (:, (i-1):i) * rot'; |
|
48 aa (:, (i-1):i) = aa (:, (i-1):i) * rot'; |
|
49 z (:, (i-1):i) = z (:, (i-1):i) * rot'; |
|
50 |
|
51 endfor |
29
|
52 endfor |
|
53 |
54
|
54 bb (2, 1) = 0.0; |
|
55 for i = 3:na |
|
56 bb (i, 1:(i-1)) = zeros (1, i-1); |
|
57 aa (i, 1:(i-2)) = zeros (1, i-2); |
|
58 endfor |
|
59 |
29
|
60 endfunction |