How to make a matrix compose by seperate optimization variables
조회 수: 1 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
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
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,
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!