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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

passing a vector into a function

JasonC
1-Newbie

passing a vector into a function

Pls. see attached PNG file, a screenshot of the page with my question in orange.

The spreadsheet is attached. The question is on the 2nd to the last page.

TIA.

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:JasonC)

It seemed to be a problem with labelling the variables - a very annoying bug in Prime. After retyping it worked.

To make it work without the range i you must use the vectorize operator.

View solution in original post

4 REPLIES 4
Werner_E
24-Ruby V
(To:JasonC)

It seemed to be a problem with labelling the variables - a very annoying bug in Prime. After retyping it worked.

To make it work without the range i you must use the vectorize operator.

Thanks!

Which text did you have to retype? I tried retyping stuff in my original file to no avail.

Also, what ambiguity does requiring the vectorize operator solve? IOW could there be another interpretation of passing a vector/matrix into a function that takes a scalar, that would be solved by requiring the vectorize operator?

Lastly, why does Mathcad Prime distinguish between range variables and vectors? What's wrong with treating them as the same thing? (or IOW, make them all vectors, with no separate "range variables"?)

For example, why not treat

x := 0,0.2..1

as a vector with 6 elements, so that v0 = 0, and v1 = 0.2, and so on? (note in "v0", 0 is a subscript)

That way you could do this legally and simply:

x = 0,0.2..1

y = x^2

...without having to do these shenanigans of creating an index variable:

i=0..5

xi=i*0.2 (note in "xi", i is a subscript)

yi=x^2 (ditto)

The extra steps to create an index range variable and seems unnecessary and annoying...


Cheers.

Werner_E
24-Ruby V
(To:JasonC)

I played around with your assignment vy[i:=.. as it looked correct and shouldn't fail. Intermediate I also got the error of i not being an integer - ridicoulous. Eventually I happend to delete the whole expression and I typed it from scratch instead of pressing undo and after doing so it worked. I am not sure what caused the error but best guess is thats it was different labelling. vx and vy are now labeled as variable and originally they were none.

Also, what ambiguity does requiring the vectorize operator solve?

Prime being so slow and awkward to use so I am too lazy to sroll upward, but I would say that its the multiplication of dt with I.90u(t..). If t is a vector both factors will be vectors, too, and so the product will be the inner scalar product rather than multiplying each elelement with its corresponding one (as vectorizing does).

We may moan about the difference between ranges and vectors and also if SMath Studio proofs that we can do without both - as long as its implemented that way we have to live with the situation and its very important to distinguish between the two.

BTW, there is an undocumented trick to turn a range into a vector - simply do an inline evaluation.

That said i:=0..5 is a range, but v:=0..5= is a vector.

That undocumented feature is great, thanks!

Top Tags