1 ## Copyright (C) 2010 Lukas F. Reichlin
3 ## This file is part of LTI Syncope.
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
19 ## @deftypefn{Function File} {@var{x} =} dlyap (@var{a}, @var{b})
20 ## @deftypefnx{Function File} {@var{x} =} dlyap (@var{a}, @var{b}, @var{c})
21 ## @deftypefnx{Function File} {@var{x} =} dlyap (@var{a}, @var{b}, @var{[]}, @var{e})
22 ## Solve discrete-time Lyapunov or Sylvester equations.
27 ## AXA' - X + B = 0 (Lyapunov Equation)
29 ## AXB' - X + C = 0 (Sylvester Equation)
31 ## AXA' - EXE' + B = 0 (Generalized Lyapunov Equation)
35 ## @strong{Algorithm}@*
36 ## Uses SLICOT SB03MD, SB04QD and SG03AD by courtesy of
37 ## @uref{http://www.slicot.org, NICONET e.V.}
39 ## @seealso{dlyapchol, lyap, lyapchol}
42 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
43 ## Created: January 2010
46 function [x, scale] = dlyap (a, b, c, e)
51 case 2 # Lyapunov equation
53 if (! is_real_square_matrix (a, b))
54 ## error ("dlyap: a, b must be real and square");
55 error ("dlyap: %s, %s must be real and square", \
56 inputname (1), inputname (2));
59 if (rows (a) != rows (b))
60 ## error ("dlyap: a, b must have the same number of rows");
61 error ("dlyap: %s, %s must have the same number of rows", \
62 inputname (1), inputname (2));
65 [x, scale] = slsb03md (a, -b, true); # AXA' - X = -B
67 ## x /= scale; # 0 < scale <= 1
69 case 3 # Sylvester equation
71 if (! is_real_square_matrix (a, b))
72 ## error ("dlyap: a, b must be real and square");
73 error ("dlyap: %s, %s must be real and square", \
74 inputname (1), inputname (2));
77 if (! is_real_matrix (c) || rows (c) != rows (a) || columns (c) != columns (b))
78 ## error ("dlyap: c must be a real (%dx%d) matrix", rows (a), columns (b));
79 error ("dlyap: %s must be a real (%dx%d) matrix", \
80 rows (a), columns (b), inputname (3));
83 x = slsb04qd (-a, b, c); # AXB' - X = -C
85 case 4 # generalized Lyapunov equation
91 if (! is_real_square_matrix (a, b, e))
92 ## error ("dlyap: a, b, e must be real and square");
93 error ("dlyap: %s, %s, %s must be real and square", \
94 inputname (1), inputname (2), inputname (4));
97 if (rows (b) != rows (a) || rows (e) != rows (a))
98 ## error ("dlyap: a, b, e must have the same number of rows");
99 error ("dlyap: %s, %s, %s must have the same number of rows", \
100 inputname (1), inputname (2), inputname (4));
103 if (! issymmetric (b))
104 ## error ("dlyap: b must be symmetric");
105 error ("dlyap: %s must be symmetric", \
109 [x, scale] = slsg03ad (a, e, -b, true); # AXA' - EXE' = -B
111 ## x /= scale; # 0 < scale <= 1
119 warning ("dlyap: solution scaled by %g to prevent overflow", scale);
131 %! B = [25.0 24.0 15.0
135 %! X = dlyap (A.', -B);
137 %! X_exp = [2.0000 1.0000 1.0000
138 %! 1.0000 3.0000 0.0000
139 %! 1.0000 0.0000 4.0000];
141 %!assert (X, X_exp, 1e-4);
153 %! C = [271.0 135.0 147.0
155 %! 578.0 383.0 287.0];
157 %! X = dlyap (-A, B, C);
159 %! X_exp = [2.0000 3.0000 6.0000
160 %! 4.0000 7.0000 1.0000
161 %! 5.0000 3.0000 2.0000];
163 %!assert (X, X_exp, 1e-4);
165 ## Generalized Lyapunov