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 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with Optimization Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!