YALMIP constraint - All values should be equal
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Johan Löfberg
il 8 Feb 2015
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
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!