Working with sets

From NA-Wiki

Jump to: navigation, search

Let say you have been defined a problem to find the minimum min(τ + ) of two sets, defined as

\tau_i^{-} = \frac{c_i - x_i}{p_i}, \quad i \in F_{-}, \quad
F_{-} = \left\{ j | j \leq l, j \in F, p_j < 0 \right\}  \\
\tau_i^{+} = \frac{d_i - x_i}{p_i}, \quad i \in F_{+}, \quad
F_{+} = \left\{ j | j \leq k, j \in F, p_j > 0 \right\}

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 j \in F. In the same way we define that if F(j) is false then j \notin F.

If you need the actual indices in F you can use the find routine

for j = find(F)
  if p(j) < 0
    % ...
Personal tools