필터 지우기
필터 지우기

YALMIP constraint - All values should be equal

조회 수: 11 (최근 30일)
SB
SB 2015년 2월 7일
댓글: SB 2015년 2월 8일
I am solving a optimization problem with different constraints and objectives using YALMIP. One of the constraints should be the following: The entries in the second row of my 3D matrix should have the same values in every third dimension. At the moment I am doing this with a for loop in the following way:
P = sdpvar(122,7,8);
Constraints = [];
for i = 2:8
Constraints = [Constraints, P(2,:,1) == P(2,:,i)];
end
So in other words this is what I want: P(2,1,1) should be the same value as P(2,1,2) and P(2,1,3) and ... and P(2,1,8). Moreover P(2,2,1) should be the same value as P(2,2,2) and P(2,2,3) and ... and P(2,2,8). And so on. But P(2,1,1) does not have to be equal to P(2,2,1) for example!
I am quite sure that the code stated above applies the constraint correctly. Is there however a better way of implementing this without a for-loop?
Or in a more general formulation: Is there a nice way of constraining all elements of a certain dimension to be the same value? Notice that this could even be a 2D matrix or a vector, the question remains the same.

채택된 답변

Johan Löfberg
Johan Löfberg 2015년 2월 8일
I believe you are implementing
diff(P(2,:,:),[],3)==
BTW, if possible, I recommend you to post YALMIP questions on the YALMIP google groups forum. More likely to get quick response
  댓글 수: 1
SB
SB 2015년 2월 8일
Yes I think that's what I was looking for! So if I understand your answer correctly, the complete constraint formulation is the following:
P = sdpvar(122,7,8);
Constraints = [];
Constraints = [Constraints, diff(P(2,:,:),1,3) == 0];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by