cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

3-Visitor

## Sum of positive values in vector and sum of negative values in a vector

I have created a vector that has both positive and negative values.

I would like to sum all the positive values, return the number, and then separately sum the negative numbers and return the number.

Is this possible?

Thanks,

Ross

1 ACCEPTED SOLUTION

Accepted Solutions
23-Emerald III
(To:RH_9815461)

Preferrably you should attach your Prime worksheet AND state which version of Prime you are using.

Attached is a Prime 4 file, with the advice from @Werner_E (see below).

Success!
Luc

7 REPLIES 7
23-Emerald III
(To:RH_9815461)

Preferrably you should attach your Prime worksheet AND state which version of Prime you are using.

Attached is a Prime 4 file, with the advice from @Werner_E (see below).

Success!
Luc

24-Ruby V
(To:LucMeekes)

You don't even need the summation operator

23-Emerald III
(To:Werner_E)

Hmm...

gives:

I think I prefer to have it in.

Or...

Now it works:

Luc

20-Turquoise
(To:LucMeekes)

24-Ruby V
(To:ttokoro)

You are correct that vectorization is not mandatory here, because the comparison v>0 is not a valid operation for vectors and so Prime automatically switches to implicit vectorization.

But I learned (sometimes by hard) that its better to explicitly use vectorization when you want it to be done and don't rely on implicit vectorization. So I got used doing so.

BTW, if you'd like to extend to also be able to deal with non-real numbers (they should be ignored as they are neither positive nor negative), it looks like we a forced to use explicit vectorization because for reasons unknown to me, logical operators like AND (^) will not be implicitly vectorized:

23-Emerald II
(To:Werner_E)

@Werner_E wrote:

You are correct that vectorization is not mandatory here, because the comparison v>0 is not a valid operation for vectors and so Prime automatically switches to implicit vectorization.

But I learned (sometimes by hard) that its better to explicitly use vectorization when you want it to be done and don't rely on implicit vectorization. So I got used doing so.

BTW, if you'd like to extend to also be able to deal with non-real numbers (they should be ignored as they are neither positive nor negative), it looks like we a forced to use explicit vectorization because for reasons unknown to me, logical operators like AND (^) will not be implicitly vectorized:

To vectorize or not to vectorize?

вот в чем вопрос.

I've just had a quick look at the MathcadPrime 7 documentation and it could do with a spot of editing to clarify which operations can be used with data types and how.

I also don't think the Is Element Of (IEO) operator () should be categorized as a comparison operator; it tests for set membership, not a comparative relation.

Here are some comments on the comparison operators and some suggestions for extending the IEO operator.  Mathcad Express 7 worksheet attached.

Data values used in the evaluations below:

Brief summary of non-vectorized comparison operations:

Observations on the IEo operator:
(I've (defined and) used the IsNatural function several times to check for positive integers in worksheets)

Outline of the concept of extending the IEO operator to "normal" data types.

Further extension of the IEO operator to operate over (predicate) function and vector values as the first argument.

I haven't proofread the worksheet, so it's likely full of grammatical and logical errors, but it's just a collection of (slightly rearranged) on-the-fly observations and thoughts.

Stuart
3-Visitor
(To:LucMeekes)

Thanks appreciate the prompt response!

Announcements
Top Tags