MATLAB Answers

Rikke
0

How to make some optimization variables equal to each other?

Rikke
さんによって質問されました 2019 年 4 月 15 日
最新アクティビティ Jon
さんによって コメントされました 2019 年 4 月 15 日
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 件のコメント

Torsten
2019 年 4 月 15 日
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.

サインイン to comment.

1 件の回答

Jon
回答者: Jon
2019 年 4 月 15 日
 採用された回答

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 件のコメント

Jon
2019 年 4 月 15 日
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.

サインイン to comment.



Translated by