How to make some optimization variables equal to each other?

5 Ansichten (letzte 30 Tage)
Rikke
Rikke am 15 Apr. 2019
Kommentiert: Jon am 15 Apr. 2019
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 Kommentar
Torsten
Torsten am 15 Apr. 2019
Bearbeitet: Torsten am 15 Apr. 2019
By reducing the number of optimization variables from 7 to 3:
A = [y(1), 0, y(2), 0, 0, 0, y(3)]
and inserting
y(1) for x(1),x(2),
y(2) for x(3),x(4),x(5) and
y(3) for x(6),x(7)
in the problem equations.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jon
Jon am 15 Apr. 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 Kommentar
Jon
Jon am 15 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by