Skip to main content
13-Aquamarine
November 5, 2025
Solved

sum and conditions of values ​​of a vector and

  • November 5, 2025
  • 3 replies
  • 471 views

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

 

Best answer by ttokoro

image.png

image.png

3 replies

23-Emerald V
November 5, 2025

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

23-Emerald V
November 6, 2025

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

ttokoro
21-Topaz I
ttokoro21-Topaz IAnswer
21-Topaz I
November 5, 2025

image.png

image.png

t.t.
25-Diamond I
November 6, 2025

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".

 

 

 

23-Emerald V
November 6, 2025

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