How to make a matrix compose by seperate optimization variables

조회 수: 1 (최근 30일)
BOWEN LI
BOWEN LI 2019년 7월 2일
편집: Matt J 2019년 7월 3일
Hi everyone,
I am thinking if it possible to put several optimizaiton variables into a matrix form. My optimization variable is defined by this syntax:
>> z1=optimvar('z1','Type','integer','LowerBound',0,'UpperBound',1)
>> z2=optimvar('z2','Type','integer','LowerBound',0,'UpperBound',1)
>> z3=optimvar('z3','Type','integer','LowerBound',0,'UpperBound',1)
zij=['z1','z2','z3';'z2','z2','z3';'z3','z3','z3']
It turns out that my 'zij' is a set of arrays not matrix. Anyone has idea about that? Thanks so much!

채택된 답변

Matt J
Matt J 2019년 7월 2일
This works fine, once you remove the quotes
>> zij=[z1,z2,z3; z2,z2,z3; z3,z3,z3];
>> showexpr(zij)
(1, 1)
z1
(2, 1)
z2
(3, 1)
z3
(1, 2)
z2
(2, 2)
z2
(3, 2)
z3
(1, 3)
z3
(2, 3)
z3
(3, 3)
z3
  댓글 수: 3
Matt J
Matt J 2019년 7월 3일
편집: Matt J 2019년 7월 3일
If all the matrix elements Zmatrix(i,j) were independent variables, you could do so as follows,
Zmatrix=optimvar('optimv',[3,3],'Type','integer','LowerBound',0,'UpperBound',1);
However, in your posted example, the Zmatrix(i,j) were not all independent of each other.
You can create a "dependent optimization variable" for your posted example like this,
z=optimvar('z',[3,1],'Type','integer','LowerBound',0,'UpperBound',1);
Zmatrix=z([ 1 2 3; 2,2,3;3 3 3]);
So, note that this Zmatrix object is of type OptimizationVariable,
Zmatrix =
3×3 OptimizationVariable array with properties:
Read-only array-wide properties:
Name: 'z'
Type: 'integer'
IndexNames: {{} {}}
Elementwise properties:
LowerBound: [3×3 double]
UpperBound: [3×3 double]
Reference to a subset of OptimizationVariable with Name 'z'.
however, it is really just a matrix of pointers, basically, to different z(i). It has no independence existence of its own. In particular, if you modify Z(1,2).LowerBound, then Z(2,1).LowerBound and Z(2,2).LowerBound will change as well, because we defined all three to be aliases of the same independent variable z(2). For additional reading,
BOWEN LI
BOWEN LI 2019년 7월 3일
Hi, I think the dependent optimization variable you said "Zmatrix" is just what I want.
Because my goal is to let Z(1,2) and Z(2,1) have the same upperbound and lowerbound while Z(1,2) and Z(2,1) reference to the same independent variable z(2). So in this case, I can multiply 'Zmatrix' with the other matrix which I also index as [1 2 3; 2,2,3;3 3 3].
So, in this sense, Z(1,3),Z(3,1),Z(3,2), and Z(3,3) all reference to z(3) right?
Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by