1 ## Copyright (C) 2009, 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{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.
30 ## Continuous or discrete-time LTI model (p-by-m, n states).
32 ## State transition matrix of discrete-time system (n-by-n).
34 ## Input matrix of discrete-time system (n-by-m).
36 ## State weighting matrix (n-by-n).
38 ## Input weighting matrix (m-by-m).
40 ## Optional cross term matrix (n-by-m). If @var{s} is not specified, a zero matrix is assumed.
42 ## Optional descriptor matrix (n-by-n). If @var{e} is not specified, an identity matrix is assumed.
48 ## State feedback matrix (m-by-n).
50 ## Unique stabilizing solution of the discrete-time Riccati equation (n-by-n).
52 ## Closed-loop poles (n-by-1).
58 ## x[k+1] = A x[k] + B u[k], x[0] = x0
61 ## J(x0) = SUM (x' Q x + u' R u + 2 x' S u)
67 ## @seealso{dare, care, lqr}
70 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
71 ## Created: November 2009
74 function [g, x, l] = dlqr (a, b, q, r = [], s = [], e = [])
76 if (nargin < 3 || nargin > 6)
84 [a, b, c, d, e, tsam] = dssdata (a, []);
88 tsam = 1; # any value > 0 could be used here
91 if (issample (tsam, -1))
92 [x, l, g] = dare (a, b, q, r, s, e);
94 [x, l, g] = care (a, b, q, r, s, e);