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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

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

RH_9815461
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?

 

RH_9815461_0-1637322354949.png

Thanks, 

 

Ross 

1 ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:RH_9815461)

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

Apart from that, how about this...

LucMeekes_0-1637325257359.png

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

 

Success!
Luc

View solution in original post

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

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

Apart from that, how about this...

LucMeekes_0-1637325257359.png

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

 

Success!
Luc

You don't even need the summation operator

Werner_E_1-1637325727922.png

 

LucMeekes
23-Emerald III
(To:Werner_E)

Hmm...

LucMeekes_0-1637325866422.png

gives:

LucMeekes_1-1637325877998.png

I think I prefer to have it in.

 

Or...

LucMeekes_2-1637326068388.png

Now it works:

LucMeekes_3-1637326087500.png

 

Luc

 

ttokoro
20-Turquoise
(To:LucMeekes)

image.pngimage.png

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:

Werner_E_0-1637409697541.png

Werner_E_1-1637409711725.png

 

StuartBruff
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:

Werner_E_0-1637409697541.png

Werner_E_1-1637409711725.png


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:
2021 11 21 B.png
 
Brief summary of non-vectorized comparison operations:
2021 11 21 C.png
 
Observations on the IEo operator:
2021 11 21 F.png
(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. 
2021 11 21 D.png
 
Further extension of the IEO operator to operate over (predicate) function and vector values as the first argument.
2021 11 21 E.png
 

 
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

Thanks appreciate the prompt response!

Top Tags