comparison scripts/control/lqr.m @ 3381:69b167451491

[project @ 1999-12-15 20:48:10 by jwe]
author jwe
date Wed, 15 Dec 1999 20:48:45 +0000
parents 8dd4718801fd
children 1a8e2c0d627a
comparison
equal deleted inserted replaced
3380:f5edd74bdc6c 3381:69b167451491
1 # Copyright (C) 1993, 1994, 1995 Auburn University. All Rights Reserved 1 ## Copyright (C) 1993, 1994, 1995 Auburn University. All Rights Reserved
2 # 2 ##
3 # This file is part of Octave. 3 ## This file is part of Octave.
4 # 4 ##
5 # Octave is free software; you can redistribute it and/or modify it 5 ## Octave is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the 6 ## under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any 7 ## Free Software Foundation; either version 2, or (at your option) any
8 # later version. 8 ## later version.
9 # 9 ##
10 # Octave is distributed in the hope that it will be useful, but WITHOUT 10 ## Octave is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details. 13 ## for more details.
14 # 14 ##
15 # You should have received a copy of the GNU General Public License 15 ## You should have received a copy of the GNU General Public License
16 # along with Octave; see the file COPYING. If not, write to the Free 16 ## along with Octave; see the file COPYING. If not, write to the Free
17 # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. 17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {[@var{k}, @var{p}, @var{e}] =} lqr (@var{a}, @var{b}, @var{q}, @var{r}, @var{z}) 20 ## @deftypefn {Function File} {[@var{k}, @var{p}, @var{e}] =} lqr (@var{a}, @var{b}, @var{q}, @var{r}, @var{z})
21 ## construct the linear quadratic regulator for the continuous time system 21 ## construct the linear quadratic regulator for the continuous time system
22 ## @iftex 22 ## @iftex
110 ## Anderson and Moore, OPTIMAL CONTROL: LINEAR QUADRATIC METHODS, 110 ## Anderson and Moore, OPTIMAL CONTROL: LINEAR QUADRATIC METHODS,
111 ## Prentice-Hall, 1990, pp. 56-58 111 ## Prentice-Hall, 1990, pp. 56-58
112 ## @end deftypefn 112 ## @end deftypefn
113 113
114 function [k, p, e] = lqr (a, b, q, r, s) 114 function [k, p, e] = lqr (a, b, q, r, s)
115 # Written by A. S. Hodel (scotte@eng.auburn.edu) August 1993.
116 115
117 # disp("lqr: entry"); 116 ## Written by A. S. Hodel (scotte@eng.auburn.edu) August 1993.
117
118 ## disp("lqr: entry");
118 119
119 if ((nargin != 4) && (nargin != 5)) 120 if ((nargin != 4) && (nargin != 5))
120 error ("lqr: invalid number of arguments"); 121 error ("lqr: invalid number of arguments");
121 endif 122 endif
122 123
123 # Check a. 124 ## Check a.
124 if ((n = is_square (a)) == 0) 125 if ((n = is_square (a)) == 0)
125 error ("lqr: requires 1st parameter(a) to be square"); 126 error ("lqr: requires 1st parameter(a) to be square");
126 endif 127 endif
127 128
128 # Check b. 129 ## Check b.
129 [n1, m] = size (b); 130 [n1, m] = size (b);
130 if (n1 != n) 131 if (n1 != n)
131 error ("lqr: a,b not conformal"); 132 error ("lqr: a,b not conformal");
132 endif 133 endif
133 134
134 # Check q. 135 ## Check q.
135
136 if ( ((n1 = is_square (q)) == 0) || (n1 != n)) 136 if ( ((n1 = is_square (q)) == 0) || (n1 != n))
137 error ("lqr: q must be square and conformal with a"); 137 error ("lqr: q must be square and conformal with a");
138 endif 138 endif
139 139
140 # Check r. 140 ## Check r.
141 if ( ((m1 = is_square(r)) == 0) || (m1 != m)) 141 if ( ((m1 = is_square(r)) == 0) || (m1 != m))
142 error ("lqr: r must be square and conformal with column dimension of b"); 142 error ("lqr: r must be square and conformal with column dimension of b");
143 endif 143 endif
144 144
145 # Check if n is there. 145 ## Check if n is there.
146 if (nargin == 5) 146 if (nargin == 5)
147 [n1, m1] = size (s); 147 [n1, m1] = size (s);
148 if ( (n1 != n) || (m1 != m)) 148 if ( (n1 != n) || (m1 != m))
149 error ("lqr: z must be identically dimensioned with b"); 149 error ("lqr: z must be identically dimensioned with b");
150 endif 150 endif
151 151
152 # Incorporate cross term into a and q. 152 ## Incorporate cross term into a and q.
153 ao = a - (b/r)*s'; 153 ao = a - (b/r)*s';
154 qo = q - (s/r)*s'; 154 qo = q - (s/r)*s';
155 else 155 else
156 s = zeros (n, m); 156 s = zeros (n, m);
157 ao = a; 157 ao = a;
158 qo = q; 158 qo = q;
159 endif 159 endif
160 160
161 # Check that q, (r) are symmetric, positive (semi)definite 161 ## Check that q, (r) are symmetric, positive (semi)definite
162 162
163 if (is_symmetric (q) && is_symmetric (r) ... 163 if (is_symmetric (q) && is_symmetric (r) ...
164 && all (eig (q) >= 0) && all (eig (r) > 0)) 164 && all (eig (q) >= 0) && all (eig (r) > 0))
165 p = are (ao, (b/r)*b', qo); 165 p = are (ao, (b/r)*b', qo);
166 k = r\(b'*p + s'); 166 k = r\(b'*p + s');
167 e = eig (a - b*k); 167 e = eig (a - b*k);
168 else 168 else
169 error ("lqr: q (r) must be symmetric positive (semi) definite"); 169 error ("lqr: q (r) must be symmetric positive (semi) definite");
170 endif 170 endif
171 171
172 # disp("lqr: exit"); 172 ## disp("lqr: exit");
173 endfunction 173 endfunction