29
|
1 function [aa,bb,q,z] = qzhess(a,b) |
|
2 |
|
3 % compute the qz decomposition of the matrix pencil (a - lambda b) |
|
4 % result: (for MATLAB compatibility): |
|
5 % q*a*z = aa, q*b*z = bb |
|
6 % q, z orthogonal, |
|
7 % v = matrix of generalized eigenvectors |
|
8 % |
|
9 % This ought to be done in a compiled program |
|
10 % Algorithm taken from Golub and Van Loan, MATRIX COMPUTATIONS, 2nd ed. |
|
11 |
|
12 [na,ma] = size(a); |
|
13 [nb,mb] = size(b); |
|
14 if( (na ~= ma) | (na ~= nb) | (nb ~= mb) ) |
|
15 disp('qz: incompatible dimensions'); |
|
16 return; |
|
17 endif |
|
18 |
|
19 % reduce to hessenberg-triangular form |
|
20 [q,bb] = qr(b); |
|
21 aa = q'*a; |
|
22 q = q'; |
|
23 z = eye(na); |
|
24 for j=1:(na-2) |
|
25 for i=na:-1:(j+2) |
|
26 %disp(['zero out aa(',num2str(i),',',num2str(j),')']) |
|
27 rot= givens(aa(i-1,j),aa(i,j)); |
|
28 aa((i-1):i,:) = rot*aa((i-1):i,:); |
|
29 bb((i-1):i,:) = rot*bb((i-1):i,:); |
|
30 q( (i-1):i,:) = rot*q( (i-1):i,:); |
|
31 |
|
32 %disp(['now zero out bb(',num2str(i),',',num2str(i-1),')']) |
|
33 rot = givens(bb(i,i),bb(i,i-1))'; |
|
34 bb(:,(i-1):i) = bb(:,(i-1):i)*rot'; |
|
35 aa(:,(i-1):i) = aa(:,(i-1):i)*rot'; |
|
36 z(:, (i-1):i) = z(:, (i-1):i)*rot'; |
|
37 endfor |
|
38 endfor |
|
39 |
|
40 bb(2,1) = 0; |
|
41 for i=3:na |
|
42 bb(i,1:(i-1)) = zeros(1,i-1); |
|
43 aa(i,1:(i-2)) = zeros(1,i-2); |
|
44 endfor |
|
45 endfunction |