How to make a matrix compose by seperate optimization variables
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
BOWEN LI
el 2 de Jul. de 2019
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 comentarios
Respuesta aceptada
Matt J
el 2 de Jul. de 2019
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 comentarios
Matt J
el 3 de Jul. de 2019
Editada: Matt J
el 3 de Jul. de 2019
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,
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!