|
Conditionally add a term in sum or other set operation |
Top Previous Next |
|
The condition
z=sum(i$(y(i) gt 0),x(i));;
says include the term for set element i only if y(i) > 0, while
z=sum((i,j)$(sameas(i,j)),x(i,j));
says add the term corresponding to a pair of set elements i and j only if the set elements have the same name (thus if the name of element i was Chicago then the j term would be included in the sum only if the name of element j was Chicago). For more on this class of conditionals see the discussion in the Conditionals chapter. For more on Sameas also see the Conditionals chapter. |