3431
|
1 ## Copyright (C) 1993, 1994, 1995 Auburn University. All rights reserved. |
|
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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301 USA. |
3431
|
19 |
|
20 ## -*- texinfo -*- |
3500
|
21 ## @deftypefn {Function File} {} dlyap (@var{a}, @var{b}) |
3431
|
22 ## Solve the discrete-time Lyapunov equation |
|
23 ## |
|
24 ## @strong{Inputs} |
|
25 ## @table @var |
|
26 ## @item a |
5016
|
27 ## @var{n} by @var{n} matrix; |
3431
|
28 ## @item b |
|
29 ## Matrix: @var{n} by @var{n}, @var{n} by @var{m}, or @var{p} by @var{n}. |
|
30 ## @end table |
|
31 ## |
5016
|
32 ## @strong{Output} |
|
33 ## @table @var |
|
34 ## @item x |
|
35 ## matrix satisfying appropriate discrete time Lyapunov equation. |
|
36 ## @end table |
|
37 ## |
3431
|
38 ## Options: |
|
39 ## @itemize @bullet |
5016
|
40 ## @item @var{b} is square: solve |
|
41 ## @iftex |
|
42 ## @tex |
|
43 ## $$ axa^T - x + b = 0 $$ |
|
44 ## @end tex |
|
45 ## @end iftex |
|
46 ## @ifinfo |
|
47 ## @code{a x a' - x + b = 0} |
|
48 ## @end ifinfo |
3431
|
49 ## @item @var{b} is not square: @var{x} satisfies either |
5016
|
50 ## @iftex |
|
51 ## @tex |
|
52 ## $$ axa^T - x + bb^T = 0 $$ |
|
53 ## @end tex |
|
54 ## @end iftex |
|
55 ## @ifinfo |
3431
|
56 ## @example |
|
57 ## a x a' - x + b b' = 0 |
|
58 ## @end example |
5016
|
59 ## @end ifinfo |
3431
|
60 ## @noindent |
|
61 ## or |
5016
|
62 ## @iftex |
|
63 ## @tex |
|
64 ## $$ a^Txa - x + b^Tb = 0, $$ |
|
65 ## @end tex |
|
66 ## @end iftex |
|
67 ## @ifinfo |
3431
|
68 ## @example |
|
69 ## a' x a - x + b' b = 0, |
|
70 ## @end example |
5016
|
71 ## @end ifinfo |
3431
|
72 ## @noindent |
|
73 ## whichever is appropriate. |
|
74 ## @end itemize |
|
75 ## |
|
76 ## @strong{Method} |
|
77 ## Uses Schur decomposition method as in Kitagawa, |
3502
|
78 ## @cite{An Algorithm for Solving the Matrix Equation @math{X = F X F' + S}}, |
3431
|
79 ## International Journal of Control, Volume 25, Number 5, pages 745--753 |
|
80 ## (1977). |
|
81 ## |
|
82 ## Column-by-column solution method as suggested in |
|
83 ## Hammarling, @cite{Numerical Solution of the Stable, Non-Negative |
5016
|
84 ## Definite Lyapunov Equation}, @acronym{IMA} Journal of Numerical Analysis, Volume |
3431
|
85 ## 2, pages 303--323 (1982). |
|
86 ## @end deftypefn |
|
87 |
|
88 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
89 ## Created: August 1993 |
|
90 |
|
91 function x = dlyap (a, b) |
|
92 |
4030
|
93 if ((n = issquare (a)) == 0) |
3431
|
94 warning ("dlyap: a must be square"); |
|
95 endif |
|
96 |
4030
|
97 if ((m = issquare (b)) == 0) |
3431
|
98 [n1, m] = size (b); |
|
99 if (n1 == n) |
|
100 b = b*b'; |
|
101 m = n1; |
|
102 else |
|
103 b = b'*b; |
|
104 a = a'; |
|
105 endif |
|
106 endif |
|
107 |
|
108 if (n != m) |
|
109 warning ("dlyap: a,b not conformably dimensioned"); |
|
110 endif |
|
111 |
|
112 ## Solve the equation column by column. |
|
113 |
|
114 [u, s] = schur (a); |
|
115 b = u'*b*u; |
|
116 |
|
117 j = n; |
|
118 while (j > 0) |
|
119 j1 = j; |
|
120 |
|
121 ## Check for Schur block. |
|
122 |
|
123 if (j == 1) |
|
124 blksiz = 1; |
|
125 elseif (s (j, j-1) != 0) |
|
126 blksiz = 2; |
|
127 j = j - 1; |
|
128 else |
|
129 blksiz = 1; |
|
130 endif |
|
131 |
|
132 Ajj = kron (s (j:j1, j:j1), s) - eye (blksiz*n); |
|
133 |
|
134 rhs = reshape (b (:, j:j1), blksiz*n, 1); |
|
135 |
|
136 if (j1 < n) |
|
137 rhs2 = s*(x (:, (j1+1):n) * s (j:j1, (j1+1):n)'); |
|
138 rhs = rhs + reshape (rhs2, blksiz*n, 1); |
|
139 endif |
|
140 |
|
141 v = - Ajj\rhs; |
|
142 x (:, j) = v (1:n); |
|
143 |
|
144 if(blksiz == 2) |
|
145 x (:, j1) = v ((n+1):blksiz*n); |
|
146 endif |
|
147 |
|
148 j = j - 1; |
|
149 |
|
150 endwhile |
|
151 |
|
152 ## Back-transform to original coordinates. |
|
153 |
|
154 x = u*x*u'; |
|
155 |
|
156 endfunction |