Matrix operator error in matlab2019a

Please, can someone help to check what maybe wrong with this code, though it is a part of the entire script
dt=1; % Time step
nHours=numel(LD);
Time=(1:nHours)';
idxHr2Toend=2:nHours;
(NOMb*SOCb(idxHr2Toend-1,:))-Et(idxHr2Toend,:)+(echb*Pbch(idxHr2Toend,:)*dt)-((Pbdch(idxHr2Toend,:)*dt)/edchb)==0;
This the error that keep showing:
Error using optim.internal.problemdef.MatrixOperator
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in
the second matrix. To perform elementwise multiplication, use '.*'.
Error in optim.internal.problemdef.Mtimes
Error in *
Error in mescode2019 (line 201)
mesprob.Constraints.Batstoredele=(NOMb*SOCb(idxHr2Toend-1,:))-Et(idxHr2Toend,:)+(echb*Pbch(idxHr2Toend,:)*dt)-((Pbdch(idxHr2Toend,:)*dt)/edchb)==0;
Thanks

Réponses (1)

Hiro Yoshino
Hiro Yoshino le 8 Jan 2020
As it said, have you tried this one?:
To perform elementwise multiplication, use '.*'.
Imagine that you want to multiply/devide the elements of two matrix (element wise)
A.*B
A./B
would work for you.

5 commentaires

tobi alabi
tobi alabi le 8 Jan 2020
thank you very much for the reply. i have tried that..
Error using optim.internal.problemdef.ElementwiseOperator/checkIsValid
Argument dimensions 24-by-1 and 23-by-1 must agree.
Error in optim.internal.problemdef.Times/checkIsValid
Error in optim.internal.problemdef.Times.getTimesOperator
Error in .*
Error in mescode2019 (line 201)
mesprob.Constraints.Batstoredele=(NOMb.*SOCb(idxHr2Toend,:))-Et(idxHr2Toend,:)+(echb.*Pbch(idxHr2Toend,:)*dt)-((Pbdch(idxHr2Toend,:)*dt)./edchb)==0;
Walter Roberson
Walter Roberson le 8 Jan 2020
What are size() of NOMb, idxHr2ToEnd, echb, dt, SOCb ?
Hiro Yoshino
Hiro Yoshino le 8 Jan 2020
As it says again...
24-by-1 and 23-by-1 must agree.
There are vectors with 24 and 23 dimensions.
You should match the numbers either 24 or 23.
As Walter Roberson mentioned, use size() command to check the size of the matries and the vectors.
tobi alabi
tobi alabi le 8 Jan 2020
thanks once again...
the model is for battery storage formulatio0n, that is why i have NOMb.*SOCb(idxHr2Toend-1,:) and Et(idxHr2Toend,:) to cater for the current time step and the previous time step i.e t and t-1
Hiro Yoshino
Hiro Yoshino le 8 Jan 2020
now that you can work on it!!

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by