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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

This value must be a vector in MPC10

Cornel
19-Tanzanite

This value must be a vector in MPC10

Hi,

Seems that Mathcad Prime 10 does not allow anymore this. How to do in this case?

Cornel_1-1714575888045.png

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Cornel)

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.

Werner_E_0-1714590661605.png

 

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:

Werner_E_1-1714592098737.png

 

You may have the idea to use "round" instead of floor, but this would yield wrong results in other cases. For example

Werner_E_2-1714591630224.png

 

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.

 

View solution in original post

18 REPLIES 18
Cornel
19-Tanzanite
(To:Cornel)

Cornel_0-1714576985272.png

Cornel
19-Tanzanite
(To:Cornel)

Here maybe is how to replicate this range definition:

Cornel_0-1714579159076.png
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 

Cornel_1-1714579312390.png

 

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?

Cornel_5-1714579814092.png

Cornel
19-Tanzanite
(To:Cornel)

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):

Cornel_1-1714580756925.png

Cornel_0-1714581145543.png

 

And what will be good is how to redefine linspace function as step range:

Cornel_5-1714580885667.png

Right now is not good:

Cornel_6-1714580914166.png

Cornel
19-Tanzanite
(To:Cornel)

And also this linspace to be made to work with units as well...will be good

LucMeekes
23-Emerald III
(To:Cornel)

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:

LucMeekes_0-1714583188703.png

and if you want units:

LucMeekes_0-1714583258514.png

and if you want it to start on another value:

LucMeekes_1-1714583294307.png

And if you want it to be a row vector:

LucMeekes_2-1714583335889.png

Success!

Luc

 

Cornel
19-Tanzanite
(To:LucMeekes)

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)

LucMeekes
23-Emerald III
(To:Cornel)

The function rangevec(f,s,l) should do what you want:

 

LucMeekes_0-1714586177610.png

LucMeekes_1-1714586201723.png

LucMeekes_2-1714586208484.png

success!
Luc

Cornel
19-Tanzanite
(To:LucMeekes)

I am not at pc now, but can be included also units in this function rangevector() and work also for negative numbers?

DJNewman
17-Peridot
(To:Cornel)

Yes for both.

DJNewman_1-1714587856991.png

 

DJNewman_2-1714588139676.png

 

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
Cornel
19-Tanzanite
(To:DJNewman)

I found another thing in Prime 10:

Cornel_0-1714589972147.png

DJNewman
17-Peridot
(To:Cornel)

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.

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
LucMeekes
23-Emerald III
(To:Cornel)

There's a very clear explanation for the result you see in Prime 10: You defined x3 as a range.

LucMeekes_1-1714596860667.png

LucMeekes_2-1714596872621.png

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.

LucMeekes_3-1714596920151.png

The funny thing occurs when you do:

LucMeekes_0-1714596845780.png

and then evaluate rws:

LucMeekes_4-1714596944516.png

 

Success!
Luc

 

Cornel
19-Tanzanite
(To:LucMeekes)

Hm...i see some diference:

1099

Cornel_0-1714588954780.png

1100

Cornel_1-1714588969702.png

 

 

Cornel
19-Tanzanite
(To:Cornel)

But also maybe one will find also as well how to do this:

Cornel_0-1714590900406.png

 

 

LucMeekes
23-Emerald III
(To:Cornel)

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

Werner_E
25-Diamond I
(To:Cornel)

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.

Werner_E_0-1714590661605.png

 

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:

Werner_E_1-1714592098737.png

 

You may have the idea to use "round" instead of floor, but this would yield wrong results in other cases. For example

Werner_E_2-1714591630224.png

 

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.

 

Cornel
19-Tanzanite
(To:Werner_E)

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.

Cornel_0-1714591638880.png

Cornel_1-1714591657590.png

 

Werner_E
25-Diamond I
(To:Werner_E)

BTW, here is a vector creation function which seems not to suffer from the problems described above.

Werner_E_2-1714592735648.png

 

Announcements

Top Tags