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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

last function... it must be a vector error

YA_10963798
12-Amethyst

last function... it must be a vector error

It shows an error although it is a vector . WHY?

YA_10963798_0-1727262651859.png

 

ACCEPTED SOLUTION

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


@YA_10963798 wrote:

That was helpful. However I used the same function on other sheet and it works perfectly. why it does not work in the new function ;]

 

 


In your 'other sheet' "z" and also "ztips" sure were vectors and not ranges. Otherwise the "last" function would again throw that error.

You can test if its vector by writing IsArray(z)= . If the result looks like a vector full of zeros, then its a range. If the result is just the number 1, its a vector.
Or you could try to access/evaluate the element #ORIGIN, If you don't get an error, its a vector.

Werner_E_2-1727271906172.png

BTW, its not a good idea and not good habit to change the value of ORIGIN in the midst of a worksheet as you have done.

 

I would suggest to create vectors right from the start if possible. But if for some reason you have to turn a range into a vector, you may use one of the utility functions which were posted here in the forum in various threads.

A very basic one is

Werner_E_0-1727271503258.png

Don't forget to label "rows" as being a "Function" as unfortunately you also have defined a numeric variable with the name "rows" in your sheet.

Then you could write something like

Werner_E_1-1727271591971.png

and z.tips will be a genuine vector.

 

View solution in original post

6 REPLIES 6
Werner_E
25-Diamond I
(To:YA_10963798)

No, its NOT a vector, its a range variable

You defined it as

Werner_E_0-1727263606536.png

and later defined

Werner_E_1-1727264064632.png

 

Ranges and vectors unfortunately look the very same in Prime but are quite different beasts.

A range is not a collection of values but rather kind of an implicit loop.

Ranges should only be used to

1) index the elements of vectors and matrices

2) provide the abscissa values for a 2D plot

3) define a for-loop in a Prime program.

 

For all other you should create vectors even though the creation of a range might be more comfortable 😉

 

I remember that at the times of good all Mathcad @StuartBruff  published two articles which still apply, explaining in details ranges vs vectors.
I guess the attached pdf contains both of them.

This topic has been a source of great confusion for ages - you are not the first to stumble across it and you probably won't be the last.

That was helpful. However I used the same function on other sheet and it works perfectly. why it does not work in the new function ;]

YA_10963798_0-1727270928226.png

 

Werner_E
25-Diamond I
(To:YA_10963798)


@YA_10963798 wrote:

That was helpful. However I used the same function on other sheet and it works perfectly. why it does not work in the new function ;]

 

 


In your 'other sheet' "z" and also "ztips" sure were vectors and not ranges. Otherwise the "last" function would again throw that error.

You can test if its vector by writing IsArray(z)= . If the result looks like a vector full of zeros, then its a range. If the result is just the number 1, its a vector.
Or you could try to access/evaluate the element #ORIGIN, If you don't get an error, its a vector.

Werner_E_2-1727271906172.png

BTW, its not a good idea and not good habit to change the value of ORIGIN in the midst of a worksheet as you have done.

 

I would suggest to create vectors right from the start if possible. But if for some reason you have to turn a range into a vector, you may use one of the utility functions which were posted here in the forum in various threads.

A very basic one is

Werner_E_0-1727271503258.png

Don't forget to label "rows" as being a "Function" as unfortunately you also have defined a numeric variable with the name "rows" in your sheet.

Then you could write something like

Werner_E_1-1727271591971.png

and z.tips will be a genuine vector.

 

I got the idea . thank you king 

StuartBruff
23-Emerald III
(To:Werner_E)

Indeed, and thanks for resurrecting my range vs vectors article.  I must see if there are any M11 -> MP10 changes that need making ... sigh, another item for my To-Procrastinate List (Surprisingly, I do have a To-Do List; it's the first item on my To-Procrastinate List! 😊).

 

However, I added an interlude to the OP's worksheet, musing upon the lack of certain Expression Type Functions (ie, IsXxxx functions), chief amongst which is IsRange.  I say "IsRange" because it's the data type that's of interest, not the variable holding the range definition.  AFAICT, there are two ways to check whether something's a range: exhaustively exclude it as any other type or use a range-only function and trap any errors.  Here's the 2nd form, the principle of which can be used in an Evaluation operator (=).  The function can only be used as intended in a Definition (:= or ≡).

 

2024 09 25 E.png

 

As several experienced users do, I have a little function or two that can convert range variables to vectors.

 

2024 09 25 F.png

 

I note, en passant, that in the original Mathcad and (IIRC) early Prime versions, you could type a range definition straight into a function as an argument. Very useful. Prime hasn't allowed this for a few versions now.  Naturally, I whined like a 3-year old about it and, so far, my entreaties have had exactly the same effect.  Excuse me for a moment while I go off and sulk.  

 

I still can't upload large files (unreliable internet service, although it's been better than the past few days), so I've copied the interlude to the attached worksheet.

 

Stuart

 

Edited: After I posted the first version of this message, I realized that I'd brain-in-neutral created the simple vec function by editing out the recursive part of the more capable vec.  However, I didn't simplify it as much as I could have and normally do.  I've amended the message and worksheet accordingly.

This is a very thorough explanation. I appreciate your taking the time to explain that way. Thank you so much . I do it the way you showed

Announcements

Top Tags