save loop data, matrix- matlab, yalmip

18 vues (au cours des 30 derniers jours)
Junhwi Mun
Junhwi Mun le 8 Juin 2020
Commenté : Junhwi Mun le 8 Juin 2020
Hi, I'm stuck on generating and keeping the outputs matrix.
As the matrix B contains 't', I should use 'for loop' to generate each solution 'PfeasibleR'
When I run it, only one solution 'PfeasibleR' at t=2 is shown. What I've done was using preallocated variable, PfeasibleR= zeros(2, 18);
Can I get some tips to save value of 'PfeasibleR' per each matrix 'B'?
ops = sdpsettings('solver','mosek','verbose',1,'debug',1);
K= 0.01; %motor torque constant= electromotive force constant
La= 0.5;%electric inductance
b= 0.1;% motor viscous friction constant
J= 0.001;%moment of inertia of the rotor
Va= 140; %armature voltage constant
Ra= 0.5;%armature electirc resistance
PfeasibleR= zeros(2, 18);
for t=0.4:0.2:2
A= [-(Ra)/La 0; 0 -b/J];
B= [0; ((K*Va)./(J*Ra))*(1-exp(-(Ra./La)*t))];
D= [0, -K./La; K./J, 0];
I=eye(1);
e_1 = 0.8;
y=sdpvar(2,1);
Pr=sdpvar(2,2);
x = sdpvar(2,1);
M=[Pr*A'+ A*Pr+ B*y'+ y*B'+ e_1*D*Pr*D' , y; y' , -e_1];%LMI
conR=[Pr>=0, M<=0]; %constraints
obR= -log(det(Pr)); %objective
optimize(conR, obR, ops)
PfeasibleR = value(Pr);%(2x2)
yfeasibleR = value(y);%(2x1)
K_R = (yfeasibleR)'/(PfeasibleR);%(1x2)
end

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Juin 2020
ops = sdpsettings('solver','mosek','verbose',1,'debug',1);
K = 0.01; %motor torque constant= electromotive force constant
La = 0.5;%electric inductance
b = 0.1;% motor viscous friction constant
J = 0.001;%moment of inertia of the rotor
Va = 140; %armature voltage constant
Ra = 0.5;%armature electirc resistance
tvals = 0.4:0.2:2; %9
num_t = length(tvals);
all_PfeasibleR = cell(1, num_t); %1 x 9
all_K_R = cell(1, num_t);
for tidx = 1 : num_t
t = tvals(tidx);
A= [-(Ra)/La 0; 0 -b/J];
B= [0; ((K*Va)./(J*Ra))*(1-exp(-(Ra./La)*t))];
D= [0, -K./La; K./J, 0];
I=eye(1);
e_1 = 0.8;
y=sdpvar(2,1);
Pr=sdpvar(2,2);
x = sdpvar(2,1);
M=[Pr*A'+ A*Pr+ B*y'+ y*B'+ e_1*D*Pr*D' , y; y' , -e_1];%LMI
conR=[Pr>=0, M<=0]; %constraints
obR= -log(det(Pr)); %objective
optimize(conR, obR, ops)
PfeasibleR = value(Pr); %(2x2)
yfeasibleR = value(y); %(2x1)
K_R = (yfeasibleR)'/(PfeasibleR); %(1x2)
all_PFeasibleR{tidx} = PFeasibleR;
all_K_R_{tidx} = K_R;
end
PFeasibleR_matrix = horzcat(all_PFeasibleR{:}]; %2 x 18
  1 commentaire
Junhwi Mun
Junhwi Mun le 8 Juin 2020
Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by