-3
$\begingroup$

Given an array of $A=[1,2,4, -5, -10, 34]$ and $A_{size} = 6$, how can I write mathematically the sum only of non-negative values? For example $S$ like $\sum_{i=1}^n (sign(A_i)\times A_i)$ but mathematically in formula ?

  • 0
    What about $\sum_{A_i \geq 0} A_i$?2017-01-03
  • 0
    Do you want the sum of the non negative values (that would be $1+2+4+34$ in your example, or the sum of the absolute values (which is what your expression - probably - gives, in your example that would be $1+2+4+5+10+34$)?2017-01-03
  • 0
    only non negative so 1,2,4,342017-01-03

1 Answers 1

2

You can write it as:

$$S^-=\frac{\sum_{i=1}^n (A_i - |A_i|)}{2}$$ $$S^+=\frac{\sum_{i=1}^n (A_i + |A_i|)}{2}$$

where $S^-$ is sum of negative elements and $S^+$ is sum of all positive elements.

  • 0
    This is what I was needed, thanks.2017-01-03
  • 0
    Possibly clearer as $\sum_i \min(A_i,0)$ and $\sum_i \max(A_i,0)$.2017-01-03