|
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