Discret time LQR R matrix must be symmetric positive definite with as many columns as B error
2 views (last 30 days)
Show older comments
Hello!
I'm trying to make a discret time control with LQR and I have this error:
Error using dlqr (line 31)
In the "lqr(A,B,Q,R,...)" command, the
R matrix must be symmetric positive
definite with as many columns as B.
Error in LQR_model2 (line 82)
K_d = dlqr(Ad,Bd,Q,R,N);
Matlab Code:
clc
clear all
close all
%% parametrii modelelului 2
Mp = 0.272;
dM = 0.071;
g = 9.81;
J = 0.002;
Jw = 3.941*10^-5;
b_theta = 0.82*10^-3;
b_altha_kmke_Ra = 1.202*10^-4;
km_Ra = 1.837*10^-4;
%% matricea modelului spatial
A = [0 1 0 0;
(Mp*dM*g)/J -(b_theta)/J 0 1/J*b_altha_kmke_Ra;
0 0 0 1;
-(Mp*g*dM)/J b_theta/J 0 -(J+Jw)/(J*Jw)*b_altha_kmke_Ra];
B = [0 0;
-1/J*km_Ra 1/J;
0 0;
(J+Jw)/(J*Jw)*km_Ra -1/J];
C = [1 0 0 0;
0 1 0 0;
0 0 1 0;
0 0 0 1];
D = [0 0; 0 0;0 0;0 0];
%% construirea sistemului
sys = ss(A,B,C,0); %construirea sistemului
xd = [50;0;200;0]; %conditii dorite
x0 = 1*randn(4,1);
%% simulare
Q = [100 0 0 0;
0 100 0 0;
0 0 10 0;
0 0 0 1];
R=5*[1 0.1;
0.1 1];
N = zeros(4,2);
[K,S,e] = lqr(sys,Q,R,N);
K_lqr = lqr(A,B,Q,R);
eig(A-B*K)
eig(A)
Acl=A-B*K
Bcl = -Acl;
sys_cl = ss(Acl,Bcl,C,0)
t_f = 30;
t = 0:0.001:t_f;
cl_intrari = [xd(1)*ones(size(t));xd(2)*ones(size(t));xd(3)*ones(size(t));xd(4)*ones(size(t))]
[iesire_cl,t_cl,s_cl] = lsim(sys_cl,cl_intrari,t,x0);
% figure;
% plot(t,s_cl(:,1),'k')
% hold on
% plot(t,s_cl(:,2),'r')
% hold on
% plot(t,s_cl(:,3),'g')
% hold on
% plot(t,s_cl(:,4),'m')
% legend('\theta','\theta dot','\alpha','\alpha dot')
% grid on
%% Discretizare
Ts = 0.1;
sys_d = c2d(sys,Ts);
Ad = sys_d.a;
Bd = sys_d.b;
Cd = sys_d.c;
Dd = sys_d.d;
R=eye(4)
K_d = dlqr(Ad,Bd,Q,R,N);
Ob = dlqr(Ad',Cd',Q,R,N);
And I tried to make R symmetric positiv and it's not working. What to do?
0 Comments
Accepted Answer
Sam Chak
on 2 Jul 2024
Fixing the code as shown will eliminate the error message.
R = eye(size(B, 2));
K_d = dlqr(Ad, Bd, Q, R, N)
R = eye(size(Cd));
N = zeros(size(Ad));
Ob = dlqr(Ad', Cd', Q, R, N)
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!