Arrays have incompatible sizes for this operation.

1 次查看(过去 30 天)
Hello,
I have this code with this error, can anyone help me please?
% Custom State Estimation
Ts=1;ts=0.1;
A=[1 0;0 1];
B=[0.0936 0.0936 0 0.0936;0 0.0752 0 0];
C=[1 0;0 1];
D=[0 0 0 0; 0 0 0 0];
plant = ss(A,B,C,D);
plant = setmpcsignals(plant,MV=[1 2 3],MD=4)
mpcobj=mpc(plant,ts,10,3)
setEstimator(mpcobj,'custom');
sys=c2d(ss(plant),Ts);
xsys=[0;0];
xmpc = mpcstate(mpcobj);
SOCpbref=75; % (en pourcentage)
SOCliref=85; % (en pourcentage)
t1=25; % en seconds
Cmaxpb=22020; % As (Ampersecond)
Cmaxli=6000; % As (Ampersecond)
Ipb=[60 65 70 75 65 60 55 50 50 50 55 60 65 70 75 75 75 75 70 60 60 55 65 60 50]; % en Ampere
Ili=[70 75 80 85 75 70 65 60 60 60 65 70 75 80 85 85 85 85 80 70 70 65 75 70 60]; % en Ampere
Cpb= sum(Ipb)/t1;
Cli= sum(Ili)/t1;
SOCpb=(Cpb/Cmaxpb);
SOCli=(Cli/Cmaxli);
for t = 0:3
y = sys.C*xsys; % plant equations: output
YY = y;
xmpc.Plant = [SOCpb, SOCli]; % state estimation
u = mpcmove(mpcobj,xmpc,[],[SOCpbref, SOCliref]); % y is not needed
UU = u;
xsys = sys.A.*xsys + sys.B.*u; % plant equations: next state
end
Arrays have incompatible sizes for this operation.
Error in customstateestimation (line 35)
xsys = sys.A.*xsys + sys.B.*u; % plant equations: next state

采纳的回答

KSSV
KSSV 2023-5-22
移动:Steven Lord 2023-5-22
sys.B is of size 2x4 and u is of size 3x1....how you can multiply them?
  1 个评论
jana nassereddine
jana nassereddine 2023-5-22
移动:Steven Lord 2023-5-22
thank you, that's true, but i cannot accept your answer because it is written as a comment

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by