]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/dlqr.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / dlqr.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}] =} dlqr (@var{sys}, @var{q}, @var{r})
20 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} dlqr (@var{sys}, @var{q}, @var{r}, @var{s})
21 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} dlqr (@var{a}, @var{b}, @var{q}, @var{r})
22 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} dlqr (@var{a}, @var{b}, @var{q}, @var{r}, @var{s})
23 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} dlqr (@var{a}, @var{b}, @var{q}, @var{r}, @var{[]}, @var{e})
24 ## @deftypefnx {Function File} {[@var{g}, @var{x}, @var{l}] =} dlqr (@var{a}, @var{b}, @var{q}, @var{r}, @var{s}, @var{e})
25 ## Linear-quadratic regulator for discrete-time systems.
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 discrete-time system (n-by-n).
33 ## @item b
34 ## Input matrix of discrete-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 discrete-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 ## x[k+1] = A x[k] + B u[k],   x[0] = x0
59 ##
60 ##         inf
61 ## J(x0) = SUM (x' Q x  +  u' R u  +  2 x' S u)
62 ##         k=0
63 ##
64 ## L = eig (A - B*G)
65 ## @end group
66 ## @end example
67 ## @seealso{dare, care, lqr}
68 ## @end deftypefn
69
70 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
71 ## Created: November 2009
72 ## Version: 0.2
73
74 function [g, x, l] = dlqr (a, b, q, r = [], s = [], e = [])
75
76   if (nargin < 3 || nargin > 6)
77     print_usage ();
78   endif
79
80   if (isa (a, "lti"))
81     s = r;
82     r = q;
83     q = b;
84     [a, b, c, d, e, tsam] = dssdata (a, []);
85   elseif (nargin < 4)
86     print_usage ();
87   else
88     tsam = 1;  # any value > 0 could be used here
89   endif
90
91   if (issample (tsam, -1))
92     [x, l, g] = dare (a, b, q, r, s, e);
93   else
94     [x, l, g] = care (a, b, q, r, s, e);
95   endif
96
97 endfunction