Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
@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.
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
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
and z.tips will be a genuine vector.
No, its NOT a vector, its a range variable
You defined it as
and later defined
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 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.
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
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
and z.tips will be a genuine vector.
I got the idea . thank you king
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 ≡).
As several experienced users do, I have a little function or two that can convert range variables to vectors.
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.