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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Translate the entire conversation x

sum and conditions of values ​​of a vector and

DC_11916766
13-Aquamarine

sum and conditions of values ​​of a vector and

Hello community, I have this problem:

  1. "How could I program it to sum 3 consecutive values in a vector (m), with the condition that the sum is performed only when there are exactly 3 consecutive values; otherwise, the result should be an empty string ('')."
  2. "What I’m trying to do here is: in vector (a), if there is even one false, the result should be false; but if all values are true, the result should be true."

DC_11916766_0-1762383073255.png

 

ACCEPTED SOLUTION

Accepted Solutions

5 REPLIES 5

I've only got Mathcad Express, so I can't do programming, but the attached Express worksheet outlines one possible method of doing what (I think) you want.

 

2020 04 05 B.png

 

A programmed version should be much simpler.

 

Stuart

I knew something was bugging me.  Clearly my subconscious knew what when I wrote "slide function f".

 

Use the convolution operators with an appropriate kernel.

 

2025 11 06 A.png

 

The operators themselves and the Diff function should give sufficient information to write a function that will vectorize over the vector and its convolution to give what's required.

 

Stuart

image.png

image.png

Werner_E
25-Diamond I
(To:DC_11916766)

Its absolutely unclear to me what your Exercise 1 should be all about and what your cases I and II should demonstrate.

In your vector m you don't have "exactly 3 consecutive" values because you have exactly seven consecutive values.

So what should the result of vector m be and how does it relate to the two "cases" you show????

As you can see, Stuart and Tetsuro interpreted your description differently, and neither of them would arrive at the vectors you specified as X and Y.

 

According your Exercise 2 I understand it in the sense that a vector which consist only of strings "True" and/or "" only should return "True" and if the vector contains just one other element (for example a string like "TRUE" or "true " or "False" or " ") the result should be "False.

This could be done that way:

Werner_E_0-1762388990595.png

Note that this corresponds to Tetsuro's second version - everything which is not a "True" or an empty string  "" triggers the result "False".

His first version on the other hand means that only a "False" triggers the result "False", everything else is allowed and returns a "True".

 

 

 

StuartBruff
23-Emerald IV
(To:Werner_E)

Unfortunately, I'm allergic to something at the moment and struggling to see, so, mea culpa, I didn't get as far as downloading the OP's worksheet and looking at the second example.  So, in partial atonement ...

 

2025 11 06 C.png

 

I wasn't sure, upon reading it, what "all true" meant, since some of the values are just empty strings, but Soln_1 is true.

 

So, I defined a predicate function "all.x?" that checks for all one value or a set of values.

 

Stuart

Announcements

Top Tags