How to make some optimization variables equal to each other?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I want that some spesific variables that are to be optimized, are to be equal to each other.
lets say that i want this: x(1)=x(2), x(3)=x(4)=x(5), x(6)=x(7)
so whatever value x(1) is optimized to, has to have the same value as x(2).
The variables that needs to be equal to each other are separated by the number 0 in a matrix:
A=[x(1), x(2) 0 x(3), x(4), x(5), 0, 0, 0, x(6), x(7) 0];
how to do this aumtomatically in matlab?
1 comentario
Respuesta aceptada
Jon
el 15 de Abr. de 2019
I assume you are using one of the MATLAB optimization functions such as fmincon or linprog. These functions include arguments Aeq,beq for equality constraints. I'm not quite clear about your indexing and the dimension of the vector x that you are trying to optimize. I think you are looking for a length twelve vector where some of the values are forced to zero and others must be equal to each other. If this is the case you could use these to enforce the constraints that you have, for example as follows:
Aeq = [1 -1 0 0 0 0 0 0 0 0 0 0;
0 0 1 -1 0 0 0 0 0 0 0 0;
0 0 1 0 -1 0 0 0 0 0 0 0;
0 0 0 0 0 1 -1 0 0 0 0 0;
0 0 1 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 1 0 0 0 0 0;
0 0 0 0 0 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 1]
beq = zeros(9,1)
so the first four rows enforce your constraints where one element has to equal another and the other 5 rows force elements of x to be equal to zero.
I would suggest though that it would be better to reformulate your problem to not have these zeros included, since you already know what there value is. In this case you would only need a length seven vector x and you could have
Aeq = [1 -1 0 0 0 0 0;
0 0 1 -1 0 0 0;
0 0 1 0 -1 0 0;
0 0 0 0 0 1 -1 ]
beq = zeros(4,1)
1 comentario
Jon
el 15 de Abr. de 2019
I didn't see Torsten's comment until after I submitted my answer, but I agree, if possible it would be preferable to reformulate your problem to just have the three optimization variables. Sometimes though this may not be so simple, or it doesn't allow a more general formulation of the problem, in which case the approach I have outlined could be used.
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.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!