save loop data, matrix- matlab, yalmip

18 ビュー (過去 30 日間)
Junhwi Mun
Junhwi Mun 2020 年 6 月 8 日
コメント済み: Junhwi Mun 2020 年 6 月 8 日
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

採用された回答

Walter Roberson
Walter Roberson 2020 年 6 月 8 日
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 件のコメント
Junhwi Mun
Junhwi Mun 2020 年 6 月 8 日
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by