245
|
1 # Copyright (C) 1993 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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
54
|
19 function [aa, bb, q, z] = qzhess (a, b) |
29
|
20 |
72
|
21 # Usage: [aa, bb, q, z] = qzhess (a, b) |
|
22 # |
54
|
23 # Compute the qz decomposition of the matrix pencil (a - lambda b) |
|
24 # |
|
25 # result: (for Matlab compatibility): |
|
26 # |
|
27 # aa = q*a*z and bb = q*b*z, with q, z orthogonal, and |
|
28 # v = matrix of generalized eigenvectors. |
|
29 # |
|
30 # This ought to be done in a compiled program |
|
31 # |
|
32 # Algorithm taken from Golub and Van Loan, Matrix Computations, 2nd ed. |
29
|
33 |
72
|
34 # Written by A. S. Hodel (scotte@eng.auburn.edu) August 1993. |
|
35 |
54
|
36 if (nargin != 2) |
|
37 error ("usage: [aa, bb, q, z] = qzhess (a, b)"); |
|
38 endif |
|
39 |
|
40 [na, ma] = size (a); |
|
41 [nb, mb] = size (b); |
|
42 if (na != ma || na != nb || nb != mb) |
|
43 error ("qzhess: incompatible dimensions"); |
|
44 endif |
|
45 |
|
46 # Reduce to hessenberg-triangular form. |
29
|
47 |
54
|
48 [q, bb] = qr (b); |
|
49 aa = q' * a; |
|
50 q = q'; |
|
51 z = eye (na); |
|
52 for j = 1:(na-2) |
|
53 for i = na:-1:(j+2) |
|
54 |
|
55 # disp (["zero out aa(", num2str(i), ",", num2str(j), ")"]) |
|
56 |
|
57 rot = givens (aa (i-1, j), aa (i, j)); |
|
58 aa ((i-1):i, :) = rot *aa ((i-1):i, :); |
|
59 bb ((i-1):i, :) = rot *bb ((i-1):i, :); |
|
60 q ((i-1):i, :) = rot *q ((i-1):i, :); |
|
61 |
|
62 # disp (["now zero out bb(", num2str(i), ",", num2str(i-1), ")"]) |
|
63 |
|
64 rot = givens (bb (i, i), bb (i, i-1))'; |
|
65 bb (:, (i-1):i) = bb (:, (i-1):i) * rot'; |
|
66 aa (:, (i-1):i) = aa (:, (i-1):i) * rot'; |
|
67 z (:, (i-1):i) = z (:, (i-1):i) * rot'; |
|
68 |
|
69 endfor |
29
|
70 endfor |
|
71 |
54
|
72 bb (2, 1) = 0.0; |
|
73 for i = 3:na |
|
74 bb (i, 1:(i-1)) = zeros (1, i-1); |
|
75 aa (i, 1:(i-2)) = zeros (1, i-2); |
|
76 endfor |
|
77 |
29
|
78 endfunction |