Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Vectorize rows and cols; a bug?

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

04-30-2016
04:47 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2016
04:47 PM

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:

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

04-30-2016
05:02 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2016
05:02 PM

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.

4 REPLIES 4

04-30-2016
05:02 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2016
05:02 PM

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.

04-30-2016
05:41 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2016
05:41 PM

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

04-30-2016
06:22 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2016
06:22 PM

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

05-24-2016
03:27 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator