YALMIP constraint - All values should be equal
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!