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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Vectorize rows and cols; a bug?

RichardJ
19-Tanzanite

Vectorize rows and cols; a bug?

This is not what I would expect for the result of vectorizing rows or cols. Vectorizing last does give me what I would expect though:

ACCEPTED SOLUTION

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

Honestly what you show is exactly what I would have expected. And I would have expected that vectorising last(V) throws an error as last(2)= would do.

Vectorising looks at all vectors in the expression and feeds the vector elements in the calculation. The results are collected in a new result vector.

So vectorising rows(V) first takes the 1 and feeds in the calculation -> rows(1) gives 0 as result and this result is the first element of the result vector. Same for 2 and 3 which gives us exactly the result vector we see.

On may argue that rows(3) or cols(2) should throw an error (like last(2) does) because the arguments are scalars and not vectors. But we used this behavior of Mathcad to see a scalar as a 0 x 0 matrix often to our advantage, when we used something like V[rows(V) <-- .... in our programs.

View solution in original post

4 REPLIES 4
Werner_E
25-Diamond I
(To:RichardJ)

Honestly what you show is exactly what I would have expected. And I would have expected that vectorising last(V) throws an error as last(2)= would do.

Vectorising looks at all vectors in the expression and feeds the vector elements in the calculation. The results are collected in a new result vector.

So vectorising rows(V) first takes the 1 and feeds in the calculation -> rows(1) gives 0 as result and this result is the first element of the result vector. Same for 2 and 3 which gives us exactly the result vector we see.

On may argue that rows(3) or cols(2) should throw an error (like last(2) does) because the arguments are scalars and not vectors. But we used this behavior of Mathcad to see a scalar as a 0 x 0 matrix often to our advantage, when we used something like V[rows(V) <-- .... in our programs.

LucMeekes
23-Emerald III
(To:RichardJ)

I disagree,

Its vectorizing rows and cols that give what you'd expect.

V has 3 rows, 1 column. But when vectorizing the 'rows(V)' statement you're actually asking: apply the rows() function to each of the elements of its argument, so to the scalars 1, 2 and 3 in turn. That gives the vector that says: 1 has 0 rows, 2 has 0 rows and 3 too.

Perfectly logical.

At first vectorizing last(V) surprised me, until I saw that vectorizing a scalar results in that scalar.

The error message for both array multiplications is "The number of rows and/or columns in these arrays do not match", which is understandable.

Luc

RichardJ
19-Tanzanite
(To:LucMeekes)

I guess you are both right. It p****d me off, because I had a rows(V) buried in a vectorized expression, which failed to work correctly because it didn't return a scalar with the number of rows in the vector. It took me a while to figure out what the problem was, and then I couldn't find a workaround that I really liked (in the end, I turned it into a two line program). So it sure felt like a bug at the time, even if it wasn't one

And in Mathcad Prime 3.1:

Pic_1.png

Announcements

Top Tags