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{u} =} lyapchol (@var{a}, @var{b})
20 ## @deftypefnx{Function File} {@var{u} =} lyapchol (@var{a}, @var{b}, @var{e})
21 ## Compute Cholesky factor of continuous-time Lyapunov equations.
26 ## A U' U + U' U A' + B B' = 0 (Lyapunov Equation)
28 ## A U' U E' + E U' U A' + B B' = 0 (Generalized Lyapunov Equation)
32 ## @strong{Algorithm}@*
33 ## Uses SLICOT SB03OD and SG03BD by courtesy of
34 ## @uref{http://www.slicot.org, NICONET e.V.}
36 ## @seealso{lyap, dlyap, dlyapchol}
39 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
40 ## Created: January 2010
43 function [u, scale] = lyapchol (a, b, e)
48 if (! is_real_square_matrix (a))
49 ## error ("lyapchol: a must be real and square");
50 error ("lyapchol: %s must be real and square", \
54 if (! is_real_matrix (b))
55 ## error ("lyapchol: b must be real")
56 error ("lyapchol: %s must be real", \
60 if (rows (a) != rows (b))
61 ## error ("lyapchol: a and b must have the same number of rows");
62 error ("lyapchol: %s and %s must have the same number of rows", \
63 inputname (1), inputname (2));
66 [u, scale] = slsb03od (a.', b.', false);
68 ## NOTE: TRANS = 'T' not suitable because we need U' U, not U U'
72 if (! is_real_square_matrix (a, e))
73 ## error ("lyapchol: a, e must be real and square");
74 error ("lyapchol: %s, %s must be real and square", \
75 inputname (1), inputname (3));
78 if (! is_real_matrix (b))
79 ## error ("lyapchol: b must be real");
80 error ("lyapchol: %s must be real", \
84 if (rows (b) != rows (a) || rows (e) != rows (a))
85 ## error ("lyapchol: a, b, e must have the same number of rows");
86 error ("lyapchol: %s, %s, %s must have the same number of rows", \
87 inputname (1), inputname (2), inputname (3));
90 [u, scale] = slsg03bd (a.', e.', b.', false);
92 ## NOTE: TRANS = 'T' not suitable because we need U' U, not U U'
100 warning ("lyapchol: solution scaled by %g to prevent overflow", scale);
106 %!shared U, U_exp, X, X_exp
108 %! A = [ -1.0 37.0 -12.0 -12.0
109 %! -1.0 -10.0 0.0 4.0
111 %! 2.0 2.0 7.0 -9.0 ].';
113 %! B = [ 1.0 2.5 1.0 3.5
115 %! -1.0 -2.5 -1.0 -1.5
117 %! -1.0 -2.5 -4.0 3.5 ].';
119 %! U = lyapchol (A, B);
121 %! X = U.' * U; # use lyap at home!
123 %! U_exp = [ 1.0000 0.0000 0.0000 0.0000
124 %! 3.0000 1.0000 0.0000 0.0000
125 %! 2.0000 -1.0000 1.0000 0.0000
126 %! -1.0000 1.0000 -2.0000 1.0000 ].';
128 %! X_exp = [ 1.0000 3.0000 2.0000 -1.0000
129 %! 3.0000 10.0000 5.0000 -2.0000
130 %! 2.0000 5.0000 6.0000 -5.0000
131 %! -1.0000 -2.0000 -5.0000 7.0000 ];
133 %!assert (U, U_exp, 1e-4);
134 %!assert (X, X_exp, 1e-4);
136 %!shared U, U_exp, X, X_exp
138 %! A = [ -1.0 3.0 -4.0
146 %! B = [ 2.0 -1.0 7.0 ].';
148 %! U = lyapchol (A, B, E);
150 %! U_exp = [ 1.6003 -0.4418 -0.1523
151 %! 0.0000 0.6795 -0.2499
152 %! 0.0000 0.0000 0.2041 ];
154 %!assert (U, U_exp, 1e-4);