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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

How to convert Data from a function into a Vector for Further use

bimam
1-Newbie

How to convert Data from a function into a Vector for Further use

Dear Community

I need help on how to convert data that are coming from a function "150" point into a vector of one column, My target is that after I finish the function I need to process this data by comparing them to a constant and divide these data based on the comparison

My work is as following

1) I have a range called z, this range is then used in a function

2) this function e(z) outputs are a range based on z

3) I then need to compare all the values that are in the range of the fn e(z) to a constant c

4) for the values that are less than c; I need to report them as is

5) for all the values that are greater than c I need to report them as c+1

6) then I want to combine all the values again in the order starting from values less than c to values greater than c

Please guide

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
StuartBruff
23-Emerald II
(To:bimam)

Bassam Imam wrote:

Dear Community

I need help on how to convert data that are coming from a function "150" point into a vector of one column, My target is that after I finish the function I need to process this data by comparing them to a constant and divide these data based on the comparison

My work is as following

1) I have a range called z, this range is then used in a function

2) this function e(z) outputs are a range based on z

3) I then need to compare all the values that are in the range of the fn e(z) to a constant c

4) for the values that are less than c; I need to report them as is

5) for all the values that are greater than c I need to report them as c+1

6) then I want to combine all the values again in the order starting from values less than c to values greater than c

Please guide

Thanks

Unfortunately, I'm without Mathcad at the moment, so will have to describe the process.

It's usually better to work with vectors than range variables for this kind of poblem or write a program, primarily because indexing with non-integer variables isn't possible directly and it requires a bit more work to set things up (nothing too difficult, just annoying).

So I'll give a vector procedure. First, define your range variable z

z :=x0,x0+step .. x1

Now you need to convert your range z to a vector. There are several ways to do this, but I find this the simplest (vec is so iseful that I define it in my Normal template).

The vec function

Have a look at the above thread and copy the function vec into yor worksheet.

Then convert z to a vector

z := vec(z)

Aply e to z

v:=e(z).  -- select the whole of the expression e(z) and apply the vectorize operator to it; this ensures that you apply e to each element of v rather than applying it to the vector.

Vector v contains your results.

Next, make use of Mathcad's Boolean operators and type

c := whatever value you want ...

v := v + (v>c).

Again, select the whole of the right hand side of the definition and apply the vectorize operator to it. Mathcad returns 1 if a Boolean is true and 0 if it's false.  So this expression will add 1 to every value greater than c.

The next thing is to sort the data.  As all values > c are greater than those that aren't , all we need do is write

v := sort(v)

Stuart

View solution in original post

4 REPLIES 4
LucMeekes
23-Emerald III
(To:bimam)

Like this?

Needless to say, E contains more that 16 values, 150 to be exact. But the last values are (too) close to zero:

Depending on your range, you may be able to directly use the above.

Attach your worksheet if you need further help.

Success!
Luc

Thanks Mr. LucMeekes for your help, I got to move around it by using vector:=range usage, how ever when I go through my sheet when using mathematical operations I need to define the vector notation on the my vector again.

In the end pity we do not have a straight forward use of range as a vector.

StuartBruff
23-Emerald II
(To:bimam)

Bassam Imam wrote:

Dear Community

I need help on how to convert data that are coming from a function "150" point into a vector of one column, My target is that after I finish the function I need to process this data by comparing them to a constant and divide these data based on the comparison

My work is as following

1) I have a range called z, this range is then used in a function

2) this function e(z) outputs are a range based on z

3) I then need to compare all the values that are in the range of the fn e(z) to a constant c

4) for the values that are less than c; I need to report them as is

5) for all the values that are greater than c I need to report them as c+1

6) then I want to combine all the values again in the order starting from values less than c to values greater than c

Please guide

Thanks

Unfortunately, I'm without Mathcad at the moment, so will have to describe the process.

It's usually better to work with vectors than range variables for this kind of poblem or write a program, primarily because indexing with non-integer variables isn't possible directly and it requires a bit more work to set things up (nothing too difficult, just annoying).

So I'll give a vector procedure. First, define your range variable z

z :=x0,x0+step .. x1

Now you need to convert your range z to a vector. There are several ways to do this, but I find this the simplest (vec is so iseful that I define it in my Normal template).

The vec function

Have a look at the above thread and copy the function vec into yor worksheet.

Then convert z to a vector

z := vec(z)

Aply e to z

v:=e(z).  -- select the whole of the expression e(z) and apply the vectorize operator to it; this ensures that you apply e to each element of v rather than applying it to the vector.

Vector v contains your results.

Next, make use of Mathcad's Boolean operators and type

c := whatever value you want ...

v := v + (v>c).

Again, select the whole of the right hand side of the definition and apply the vectorize operator to it. Mathcad returns 1 if a Boolean is true and 0 if it's false.  So this expression will add 1 to every value greater than c.

The next thing is to sort the data.  As all values > c are greater than those that aren't , all we need do is write

v := sort(v)

Stuart

bimam
1-Newbie
(To:bimam)

Very descriptive thanks for your help, I got through by vector notation on each step,

Thanks again

Top Tags