Unable to perform assignment because the left and right sides have a different number of elements.

6 visualizaciones (últimos 30 días)
Hello everyone, so I have this code with this error:
% 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(t+1) = y;
xmpc.Plant = [SOCpb, SOCli]; % state estimation
u = mpcmove(mpcobj,xmpc,[],[SOCpbref, SOCliref]); % y is not needed
UU(t+1) = u;
xsys = sys.A.*xsys + sys.B.*u; % plant equations: next state
end
Unable to perform assignment because the left and right sides have a different number of elements.
Error in customstateestimation (line 28)
YY(t+1) = y;

Respuesta aceptada

Askic V
Askic V el 22 de Mayo de 2023
Not really sure what you're trying to simulate here.
From what I can see in the code, you have created a MIMO system with 4 inputs and 2 outputs. Out of these 4 inputs, 3 inputs are manipulted variable and 4th input is measured disturbance.
When simulating systems in statespace, you shouldn't use element wise operations such as multiplication, but bnormal multiplication, since dimensions must agree.
So in addition to what @KSSV already suggested, you need to pay attention to the fact that line u = mpcmove(mpcobj,xmpc,... wil produce vector u with three elements i.e. dimension 3x1. So again, you'll have a mismatch.
One way to overcome this would be the following:
for t = 0:3
y = sys.C*xsys; % plant equations: output
YY(t+1,:) = y;
xmpc.Plant = [SOCpb, SOCli]; % state estimation
u = mpcmove(mpcobj,xmpc,[],[SOCpbref, SOCliref]); % y is not needed
u = [u;0]; % add 4th row in order to match dimensions
UU(t+1,:) = u;
xsys = sys.A*xsys + sys.B*u; % plant equations: next state, no need for element-wise operation
end
but in the end, you need to confirm is this what you expect it to be.

Más respuestas (1)

KSSV
KSSV el 22 de Mayo de 2023
Repalce
YY(t+1) = y;
UU(t+1) = u;
with
YY(t+1,:) = y;
UU(t+1,:) = u;

Categorías

Más información sobre General Applications en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by