DLQR Matlab
DLQR Matlab
DLQR Matlab
Search codes
error(nargchk(4,5,nargin));
error(abcdchk(a,b));
if ~length(a) | ~length(b)
error('A and B matrices cannot be empty.')
end
[m,n] = size(a);
[mb,nb] = size(b);
[mq,nq] = size(q);
if (m ~= mq) | (n ~= nq)
error('A and Q must be the same size');
end
[mr,nr] = size(r);
if (mr ~= nr) | (nb ~= mr)
error('B and R must be consistent');
end
if nargin==5
[mn,nnn] = size(nn);
if (mn ~= m) | (nnn ~= nr), error('N must be consistent with Q and R'); end
% Add cross term
q = q - nn/r*nn';
a = a - b/r*nn';
else
nn = zeros(m,nb);
end
% eigenvectors of Hamiltonian
[v,d] = eig([a+b/r*b'/a'*q -b/r*b'/a'; -a'\q inv(a)']);
read.pudn.com/downloads40/sourcecode/book/139496/control/DLQR.M__.htm 1/2
07/02/2020 ͨ ϵ MATLAB (Proakis) source code.zip DLQR.M
d = diag(d);
[e,index] = sort(abs(d)); % sort on magnitude of eigenvalues
if (~((e(n) < 1) & (e(n+1)>1)))
error('Can''t order eigenvalues, (A,B) may be uncontrollable.');
else
e = d(index(1:n));
end
% select vectors with eigenvalues inside unit circle
chi = v(1:n,index(1:n));
lambda = v((n+1):(2*n),index(1:n));
s = real(lambda/chi);
k = (r+b'*s*b)\b'*s*a + r\nn';
read.pudn.com/downloads40/sourcecode/book/139496/control/DLQR.M__.htm 2/2