]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/lqr.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / lqr.m
1 ## Copyright (C) 2009, 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{g}, @var{x}, @var{l}] =} lqr (@var{sys}, @var{q}, @var{r})
20 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} lqr (@var{sys}, @var{q}, @var{r}, @var{s})
21 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} lqr (@var{a}, @var{b}, @var{q}, @var{r})
22 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} lqr (@var{a}, @var{b}, @var{q}, @var{r}, @var{s})
23 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} lqr (@var{a}, @var{b}, @var{q}, @var{r}, @var{[]}, @var{e})
24 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} lqr (@var{a}, @var{b}, @var{q}, @var{r}, @var{s}, @var{e})
25 ## Linear-quadratic regulator.
26 ##
27 ## @strong{Inputs}
28 ## @table @var
29 ## @item sys
30 ## Continuous or discrete-time LTI model (p-by-m, n states).
31 ## @item a
32 ## State transition matrix of continuous-time system (n-by-n).
33 ## @item b
34 ## Input matrix of continuous-time system (n-by-m).
35 ## @item q
36 ## State weighting matrix (n-by-n).
37 ## @item r
38 ## Input weighting matrix (m-by-m).
39 ## @item s
40 ## Optional cross term matrix (n-by-m).  If @var{s} is not specified, a zero matrix is assumed.
41 ## @item e
42 ## Optional descriptor matrix (n-by-n).  If @var{e} is not specified, an identity matrix is assumed.
43 ## @end table
44 ##
45 ## @strong{Outputs}
46 ## @table @var
47 ## @item g
48 ## State feedback matrix (m-by-n).
49 ## @item x
50 ## Unique stabilizing solution of the continuous-time Riccati equation (n-by-n).
51 ## @item l
52 ## Closed-loop poles (n-by-1).
53 ## @end table
54 ##
55 ## @strong{Equations}
56 ## @example
57 ## @group
58 ## .
59 ## x = A x + B u,   x(0) = x0
60 ##
61 ##         inf
62 ## J(x0) = INT (x' Q x  +  u' R u  +  2 x' S u)  dt
63 ##          0
64 ##
65 ## L = eig (A - B*G)
66 ## @end group
67 ## @end example
68 ## @seealso{care, dare, dlqr}
69 ## @end deftypefn
70
71 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
72 ## Created: November 2009
73 ## Version: 0.2
74
75 function [g, x, l] = lqr (a, b, q, r = [], s = [], e = [])
76
77   if (nargin < 3 || nargin > 6)
78     print_usage ();
79   endif
80
81   if (isa (a, "lti"))
82     s = r;
83     r = q;
84     q = b;
85     [a, b, c, d, e, tsam] = dssdata (a, []);
86   elseif (nargin < 4)
87     print_usage ();
88   else
89     tsam = 0;
90   endif
91
92   if (issample (tsam, -1))
93     [x, l, g] = dare (a, b, q, r, s, e);
94   else
95     [x, l, g] = care (a, b, q, r, s, e);
96   endif
97
98 endfunction