Working with sets
From NA-Wiki
Let say you have been defined a problem to find the minimum min(τ^{ − },τ^{ + }) of two sets, defined as
How would you do that in Matlab? How do you do it efficiently in Matlab?
Let the variables in the following program be defined as following,
Matlab variable | Math. definition |
Fp | F^{ + } |
Fm | F^{ − } |
Tp | τ^{ + } |
Tm | τ^{ − } |
First if we have more than k elements in F or p
Fp = F(1:k) & p(1:k) > 0; Fm = F(1:k) & p(1:k) < 0; Tp = (c(Fp)-x(Fp))./p(Fp); Tm = (c(Fm)-x(Fm))./p(Fm);
If we have exactly k elements in F and p then we can just say
Fp = F & p > 0; Fm = F & p < 0; Tp = (c(Fp)-x(Fp))./p(Fp); Tm = (c(Fm)-x(Fm))./p(Fm);
The vectors Fp and Fm are defined as a vector with length k, where k is the number of elements in the universal set that F lives in. We define that if F(j) is true then . In the same way we define that if F(j) is false then .
If you need the actual indices in F you can use the find routine
for j = find(F) if p(j) < 0 % ... end end