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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Vector less or bigger than

fjacobsen
1-Newbie

Vector less or bigger than

Hi.

I'm trying to output a vector based on a vector made by range variables. I'm not sure how to start this so any help is appreciated.

My input vector 5x1 and I want one output vector to give me a 3x1 one vector based on values in my vector which is bigger than value a and one output vector which is smaller than a. See attached for more info.

I can kind of solve it but I want the output vectors to be 3x1 and 2x1 vectors with no zeroes.

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions

Here's one way.

Alan

View solution in original post

5 REPLIES 5

Here's one way.

Alan

Thank you, Alan!

That's perfect!

Some questions. Sorry if this should be obvious.

Can you explain the program step by step?

The things I'm wondering about are these:

1. Why start the program defining p as zero?

2. I'm not getting the grip with what is happening after the if statement with d3[p

Fredrik Jacobsen wrote:

Thank you, Alan!

That's perfect!

Some questions. Sorry if this should be obvious.

Can you explain the program step by step?

The things I'm wondering about are these:

1. Why start the program defining p as zero?

p is an index to positions in the vector d3 which will contain the items of d when d>a. Mathcad starts counting at zero, so I set it to zero to start. After it has been used it is incremented by 1. (You could start it at -1 and then, when you need to use it, increment it before assigning a value to that position in d3 etc.).

2. I'm not getting the grip with what is happening after the if statement with d3[p

Within the if statement there are two assignments. The first assigns the k'th value of d (corresponding to a non-zero value in d>a ) to the p'th position in d3. The second assignment then increments p by 1, ready for the next non-zero assignment to the next position in d3. p only increments when a non-zero value has been observed in d>a.

The final statement of the program simply returns the whole vector of values that have been stored in d3.

Alan

Here is a different way of achieving what you demandend, following your appraoch of using the vector of boolean values you calculated first. All you missed was trimming out the zeros which is what the built-in function trim() can do. trim() is part of an extension pack which usually is included in the normal Mathcad distribution but chances are that its not part of an educational license. If thats the case come back here for an alternative to trim().

1.png

That also worked nice, and very simple.

Thanks Werner!

Top Tags