How can i sum only positive numbers in series like below:
For example i have a series like;
(10-x)
(3-x)
(4-x)
(15-x)
when i sum it up my equation is : (32-4x)
For x=6 result is 8
but i only want to sum positive numbers
(10-6)=4
(3-6)=-3
(4-6)=-2
(15-6)=9
when i sum only positive number result is 13. so 32-4x not working for me. what should my equation be for summing only positive numbers?
Thanks a lot.
This can be obtained with the absolute value
$$\sum_k\frac{(c_k-x)+|c_k-x|}2$$ to cancel out the negative terms.
$$\frac{32-4x+|10-x|+|3-x|+|4-x|+|15-x|}2.$$
As the function is piecewise linear and the constants seem irregular, there is no way to simplify it.
It is also customary to denote the positive part of an expression with a $+$ exponent, giving
$$\sum_k(c_k-x)^+=\sum_k\max(0,c_k-x).$$