Discret time LQR R matrix must be symmetric positive definite with as many columns as B error

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Sam Chak
Sam Chak am 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)
K_d = 2x4
0.6249 0.8269 2.4984 0.8009 0.2062 0.0264 0.0001 0.0001
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
R = eye(size(Cd));
N = zeros(size(Ad));
Ob = dlqr(Ad', Cd', Q, R, N)
Ob = 4x4
1.4894 10.6811 -0.4535 -9.2995 0.1132 1.4441 -0.0141 -0.4215 -0.0000 -0.0001 0.9165 0.0030 -0.0032 -0.0258 0.0887 0.7332
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by