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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

6-Contributor

## Flip or swap a vector

Hi,

a very simple problem:

I want to flip a vector, that means reverse the sequence of its elements for example (1,2,3)  -->  (3,2,1). I tried several methods, none works really.

The problem is, the result vector seems to be ok, but if I use it in other expressions together with the vectorize operator MathCad says always this value has to be a vector.

I am using Prime 3.0. Thanks

11 REPLIES 11
24-Ruby IV
(To:Manfred_F)

There is a built-in function. Or you would like to create own one?

6-Contributor
(To:Manfred_F)

Hi Valery,

sorry didn't know this function. but the problem stays the same. The only workaround I found by now is to assign a variable and then use the vectorize operation. Seems that the vectorize operator somehow does not work on functions, which have a vector as result?

23-Emerald I
(To:Manfred_F)

"vectorize" means "take the vectors under the arrow apart and do this operation on each element, leave the result in a vector with the same number of elements.."

When you vectorize your function, Mathcad takes the first element of the vector and tries to sort it into three parts--it can't

Besides, there's a command "reverse"

24-Ruby IV
(To:Fred_Kohlhepp)
 Fred Kohlhepp написал(а): "vectorize" means

One good example

6-Contributor
(To:Fred_Kohlhepp)

Ok I understand, even if it looks not logical to me. I had to convert from MathCad15 to Prime 3.0 and in MathCad 15 it somehow works with the reverse function:

is it a bug or a feature ?

23-Emerald I
(To:Manfred_F)

Apparently in version 15 the built-in reverse function was immune.  That is not true in Prime

23-Emerald II
(To:Fred_Kohlhepp)
 Fred Kohlhepp wrote: Apparently in version 15 the built-in reverse function was immune.  That is not true in Prime Bug or feature?  Your call!!

I'd hope for consistent behaviour in an application.  In this case, I'd expect the vectorize operator to apply to everything in its scope, so (IMO) Prime works "correctly" in this instance rather then M15.   So, the only way round it is to use the normal workround of assigning reverse(v) to another variable first (as mentioned).

Stuart

1-Newbie
(To:Manfred_F)

The problem can be solved by defining a function which mulitplies vectors, so the program is forced to first calculate the vectors and then vectorize them (see case 3 with the multiVec function).

23-Emerald III
(To:Manfred_F)

I'd say: one more thing broken in Prime vs Mathcad (11):

Luc

Related:

This shows that the vectorize modifier vectorizes all operations under the modifier, not just the single operator you may be intending to modify.

3-Visitor
(To:Manfred_F)

Announcements
Top Tags