comparison scripts/control/base/lqr.m @ 7126:4a375de63f66

[project @ 2007-11-08 03:44:14 by jwe]
author jwe
date Thu, 08 Nov 2007 03:44:15 +0000
parents a1dbe9d80eee
children
comparison
equal deleted inserted replaced
7125:f084ba47812b 7126:4a375de63f66
117 117
118 function [k, p, e] = lqr (a, b, q, r, s) 118 function [k, p, e] = lqr (a, b, q, r, s)
119 119
120 ## disp("lqr: entry"); 120 ## disp("lqr: entry");
121 121
122 if ((nargin != 4) && (nargin != 5)) 122 if (nargin != 4 && nargin != 5)
123 error ("lqr: invalid number of arguments"); 123 error ("lqr: invalid number of arguments");
124 endif 124 endif
125 125
126 ## Check a. 126 ## Check a.
127 if ((n = issquare (a)) == 0) 127 if ((n = issquare (a)) == 0)
133 if (n1 != n) 133 if (n1 != n)
134 error ("lqr: a,b not conformal"); 134 error ("lqr: a,b not conformal");
135 endif 135 endif
136 136
137 ## Check q. 137 ## Check q.
138 if ( ((n1 = issquare (q)) == 0) || (n1 != n)) 138 if ((n1 = issquare (q)) == 0 || n1 != n)
139 error ("lqr: q must be square and conformal with a"); 139 error ("lqr: q must be square and conformal with a");
140 endif 140 endif
141 141
142 ## Check r. 142 ## Check r.
143 if ( ((m1 = issquare(r)) == 0) || (m1 != m)) 143 if ((m1 = issquare(r)) == 0 || m1 != m)
144 error ("lqr: r must be square and conformal with column dimension of b"); 144 error ("lqr: r must be square and conformal with column dimension of b");
145 endif 145 endif
146 146
147 ## Check if n is there. 147 ## Check if n is there.
148 if (nargin == 5) 148 if (nargin == 5)
149 [n1, m1] = size (s); 149 [n1, m1] = size (s);
150 if ( (n1 != n) || (m1 != m)) 150 if (n1 != n || m1 != m)
151 error ("lqr: z must be identically dimensioned with b"); 151 error ("lqr: z must be identically dimensioned with b");
152 endif 152 endif
153 153
154 ## Incorporate cross term into a and q. 154 ## Incorporate cross term into a and q.
155 ao = a - (b/r)*s'; 155 ao = a - (b/r)*s';
160 qo = q; 160 qo = q;
161 endif 161 endif
162 162
163 ## Check that q, (r) are symmetric, positive (semi)definite 163 ## Check that q, (r) are symmetric, positive (semi)definite
164 164
165 if (issymmetric (q) && issymmetric (r) ... 165 if (issymmetric (q) && issymmetric (r)
166 && all (eig (q) >= 0) && all (eig (r) > 0)) 166 && all (eig (q) >= 0) && all (eig (r) > 0))
167 p = are (ao, (b/r)*b', qo); 167 p = are (ao, (b/r)*b', qo);
168 k = r\(b'*p + s'); 168 k = r\(b'*p + s');
169 e = eig (a - b*k); 169 e = eig (a - b*k);
170 else 170 else
171 error ("lqr: q (r) must be symmetric positive (semi) definite"); 171 error ("lqr: q (r) must be symmetric positive (semi) definite");
172 endif 172 endif
173 173
174 ## disp("lqr: exit");
175 endfunction 174 endfunction