]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/dlyapchol.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / dlyapchol.m
1 ## Copyright (C) 2010   Lukas F. Reichlin
2 ##
3 ## This file is part of LTI Syncope.
4 ##
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.
9 ##
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.
14 ##
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/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn{Function File} {@var{u} =} dlyapchol (@var{a}, @var{b})
20 ## @deftypefnx{Function File} {@var{u} =} dlyapchol (@var{a}, @var{b}, @var{e})
21 ## Compute Cholesky factor of discrete-time Lyapunov equations.
22 ##
23 ## @strong{Equations}
24 ## @example
25 ## @group
26 ## A U' U A'  -  U' U  +  B B'  =  0           (Lyapunov Equation)
27 ##
28 ## A U' U A'  -  E U' U E'  +  B B'  =  0      (Generalized Lyapunov Equation)
29 ## @end group
30 ## @end example
31 ##
32 ## @strong{Algorithm}@*
33 ## Uses SLICOT SB03OD and SG03BD by courtesy of
34 ## @uref{http://www.slicot.org, NICONET e.V.}
35 ##
36 ## @seealso{dlyap, lyap, lyapchol}
37 ## @end deftypefn
38
39 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
40 ## Created: January 2010
41 ## Version: 0.2.1
42
43 function [u, scale] = dlyapchol (a, b, e)
44
45   switch (nargin)
46     case 2
47       
48       if (! is_real_square_matrix (a))
49         ## error ("dlyapchol: a must be real and square");
50         error ("dlyapchol: %s must be real and square", \
51                 inputname (1));
52       endif
53
54       if (! is_real_matrix (b))
55         ## error ("dlyapchol: b must be real")
56         error ("dlyapchol: %s must be real", \
57                 inputname (2))
58       endif
59   
60       if (rows (a) != rows (b))
61         ## error ("dlyapchol: a and b must have the same number of rows");
62         error ("dlyapchol: %s and %s must have the same number of rows", \
63                 inputname (1), inputname (2));
64       endif
65
66       [u, scale] = slsb03od (a.', b.', true);
67
68       ## NOTE: TRANS = 'T' not suitable because we need U' U, not U U'
69
70     case 3
71
72       if (! is_real_square_matrix (a, e))
73         ## error ("dlyapchol: a, e must be real and square");
74         error ("dlyapchol: %s, %s must be real and square", \
75                 inputname (1), inputname (3));
76       endif
77
78       if (! is_real_matrix (b))
79         ## error ("dlyapchol: b must be real");
80         error ("dlyapchol: %s must be real", \
81                 inputname (2));
82       endif
83
84       if (rows (b) != rows (a) || rows (e) != rows (a))
85         ## error ("dlyapchol: a, b, e must have the same number of rows");
86         error ("dlyapchol: %s, %s, %s must have the same number of rows", \
87                 inputname (1), inputname (2), inputname (3));
88       endif
89
90       [u, scale] = slsg03bd (a.', e.', b.', true);
91
92       ## NOTE: TRANS = 'T' not suitable because we need U' U, not U U'
93
94     otherwise
95       print_usage ();
96
97   endswitch
98
99   if (scale < 1)
100     warning ("dlyapchol: solution scaled by %g to prevent overflow", scale);
101   endif
102
103 endfunction
104
105
106 ## TODO: add tests