Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hi,
Seems that Mathcad Prime 10 does not allow anymore this. How to do in this case?
Solved! Go to Solution.
I already mention the fact that this undocumented trick does not work anymore in a former thread and provided a range2vec function.
But of course it would be easier to use a function which creates the vector right ahead.
But to quickly fix older worksheets the function may come handy.
In the past many functions which would create a vector were posted now and then. Some follow the syntax of a range definition and require the user to provide first, second and last value. Due to numerical round-off errors some of those functions suffer from the problem that the number of elements is calculated wrong and the last value is missing.
See here why "rangevec" fails with your example:
You may have the idea to use "round" instead of floor, but this would yield wrong results in other cases. For example
BTW, on contrary to Luc I won't call it an improvement when a convenient, but undocumented feature is ditched without providing an at least equally convenient official, 'legal' replacement - either for turning a range into a vector or for quickly creating the desired vector right ahead.
Here maybe is how to replicate this range definition:
Being also interested in how a linspace function could be defined in Mathcad prime as I saw that it does not exist, I came across an older topic:
https://community.ptc.com/t5/Mathcad/Does-anyone-know-how-to-plot-something-like-this-in-mathcad/td-p/59034
But what I do not like at this program is that step is defined as something like below with x starting value, y ending value and z step. How could this program (or another create another program, this program is example that I could find) be changed in order that the step z to be defined as z-x. Or how could this program be changed in order to have linspace(x,y,z) as is the case of step range defined default be mathcad, with x starting value, specified step y-x, and ending value z?
Something like that as linspace function seems to work better than step range defined by mathcad operator even in mathcad prime 9 (without the need to show t1 step range):
And what will be good is how to redefine linspace function as step range:
Right now is not good:
And also this linspace to be made to work with units as well...will be good
Yes, Prime 10 was improved with respect to Prime 9. PTC ditched some undocumented behaviour.
Now you can use linspace() to create a vector of linearly separated values, but...
You can also do this:
and if you want units:
and if you want it to start on another value:
And if you want it to be a row vector:
Success!
Luc
It's good to know that there are other posibilities of creating a step range/linspace values, but lets work around for now on this posted function linspace or creating other program (with the same function name linspace) that behaves as step range, and to make linspace to have the same behaviour as step range as I suggested above (like t3=linspace(x, y1, z) to have the same values as when defining step range t1=x, y1...z)
The function rangevec(f,s,l) should do what you want:
success!
Luc
I am not at pc now, but can be included also units in this function rangevector() and work also for negative numbers?
Yes for both.
I found another thing in Prime 10:
Well, yeah, in-line evaluating range variables no longer create vectors in Prime 10 versus earlier versions, and only vectors/matrices have rows or columns, so using rows() or cols() on a non-vector/matrix gives 0.
PTC is internally monitoring the whole range to vector issue closely, but it's premature for me to offer any flavour beyond that.
There's a very clear explanation for the result you see in Prime 10: You defined x3 as a range.
Then evaluating rows(x3) means you ask Prime to give the number of rows for each of the values in the range x3. Well, 0 has 0 rows, 1 has 0 rows ... 10 has 0 rows.
The funny thing occurs when you do:
and then evaluate rws:
Success!
Luc
Hm...i see some diference:
1099
1100
But also maybe one will find also as well how to do this:
If you change 'floor' to 'ceil' in the rangevec() function, it will produce elements 0 through 1100, just as the range does.
But it might keep, or introduce, another edge case where the two produce different results.
Success!
Luc
I already mention the fact that this undocumented trick does not work anymore in a former thread and provided a range2vec function.
But of course it would be easier to use a function which creates the vector right ahead.
But to quickly fix older worksheets the function may come handy.
In the past many functions which would create a vector were posted now and then. Some follow the syntax of a range definition and require the user to provide first, second and last value. Due to numerical round-off errors some of those functions suffer from the problem that the number of elements is calculated wrong and the last value is missing.
See here why "rangevec" fails with your example:
You may have the idea to use "round" instead of floor, but this would yield wrong results in other cases. For example
BTW, on contrary to Luc I won't call it an improvement when a convenient, but undocumented feature is ditched without providing an at least equally convenient official, 'legal' replacement - either for turning a range into a vector or for quickly creating the desired vector right ahead.
Ok, I see. If someone will find also how to modify the above posted linspace() function in order to have same behaviour as step range operator and to see how will work also this linspace function, then will be also good. Anyway is ok so far either with range2vect() function.
BTW, here is a vector creation function which seems not to suffer from the problems described above.