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}] =} 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.
30 ## Continuous or discrete-time LTI model (p-by-m, n states).
32 ## State transition matrix of continuous-time system (n-by-n).
34 ## Input matrix of continuous-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 continuous-time Riccati equation (n-by-n).
52 ## Closed-loop poles (n-by-1).
59 ## x = A x + B u, x(0) = x0
62 ## J(x0) = INT (x' Q x + u' R u + 2 x' S u) dt
68 ## @seealso{care, dare, dlqr}
71 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
72 ## Created: November 2009
75 function [g, x, l] = lqr (a, b, q, r = [], s = [], e = [])
77 if (nargin < 3 || nargin > 6)
85 [a, b, c, d, e, tsam] = dssdata (a, []);
92 if (issample (tsam, -1))
93 [x, l, g] = dare (a, b, q, r, s, e);
95 [x, l, g] = care (a, b, q, r, s, e);