MATLAB Answers


multidimensional matrix optimization error

Asked by BOWEN LI on 20 Jul 2019
Latest activity Commented on by BOWEN LI on 24 Jul 2019
Hello everyone,
I have an optimization variable
and I want to put this "y" into a matrix which have 4 time periods, so i created a multidimensional matrix as this:
yi=y([ 1 2 3 4; 2 2 3 4;3 3 3 4;4 4 4 4]);
yi(:,:,2)= y([ 1 2 3 4; 2 2 3 4;3 3 3 4;4 4 4 4]);
yi(:,:,3)= y([ 1 2 3 4; 2 2 3 4;3 3 3 4;4 4 4 4]);
yi(:,:,4)= y([ 1 2 3 4; 2 2 3 4;3 3 3 4;4 4 4 4]);
where the third dimension is about time, which I have 4 years in my problem. While I run this code in matlab it says this is an illegal assignment, could anyone help me with that?
Thank you!


Show 1 older comment
Thank you for editing and answering my question. And sorry for the description.
I intend to design a time-series matrix which is designed for 4 years, namely in each year, there is a matrix "y", and all elements of "y" are binary decision variables that they may turn to 1 from 0 in one year and then stay on 1. Specifically, the layouts of matrix "y" has to be in the special form as shown in "yi".
I just changed my code as below, I hope this would work
yi=[y(1,1,1),y(2,1,1),y(3,1,1),y(4,1,1);y(2,1,1),y(2,1,1),y(3,1,1),y(4,1,1);y(3,1,1),y(3,1,1),y(3,1,1),y(4,1,1);y(4,1,1),y(4,1,1),y(4,1,1),y(4,1,1)]; %create binary decision variable yit
on 21 Jul 2019
>> whos yi
Name Size Bytes Class Attributes
yi 4x4x4 512 double
yi is a 4x4x4 array...I don't follow what your intention really is, just what you created is above.
I also don't fully understand the doc with optimvar and how the problem setup would work so am just throwing darts here--and the crystal ball is dark.
thank you again for your answer!
let me try to make this clearer, basically i have y1 y2 y3 and y4, which are binary decision variables (0 or 1). And i create these y1 - y4 by optimvar which will be used in a optimization toolbox.
Also, y1 - y4 are originally all equal to 0,then at some point (in year 1, year 2, year 3, year 4) they turn to 1. So i have to make a third dimension which is about time.
And the matrix has to be in the form below, that y1 - y4 has to be in their specific position shown in the matrix.
yi = [y1 y2 y3 y4
y2 y2 y3 y4
y3 y3 y3 y4
y4 y4 y4 y4]
So in order to add a third dimension that is to make a three dimensinal matrix, i'm wondering how. First of all, I tried to make yi a 3D matrix, that does not work with optimvar. Then, i made y1 - y4 3D dimensional optimization variables, and put them according to the loayout of matrix yi.
Sorry for any misunderstandings, I sometimes need to review a lot to make these things clear. Thank you!

Sign in to comment.

1 Answer

Answer by Kavya Vuriti on 24 Jul 2019
 Accepted Answer

From the question I understand that you created an optimization variable y and wants to create a 3-dimensional matrix yi in a specific layout where the 3rd dimension is time.
Try using the following code:
Hope it works.
For more information on creating multi-dimensional binary optimization variables, you can refer the following link:

  1 Comment

Thank you so much! I will try with yours. Appreciate for your answer.

Sign in to comment.