Skip to main content
1-Visitor
September 23, 2013
Solved

Error with array dimensions

  • September 23, 2013
  • 2 replies
  • 4643 views

Hello everyone,

I'm trying to square the the values in a non-square matrix in a function. In order to do this, I use the vectorize operator above the operation (squaring or multiplying the radii together). However, I'm getting an error in this step, which appears due to the definition of the function. I'm not able to determine the cause, as if I were to perform the operation on a copy of the matricies, it works just fine. Furthermore, I've used the operation in a fuction definition other places in the file.

Thank you!

error.png

Best answer by Werner_E

It seems to me that the problem is that if you vectorize the squaring you automatically also vectorize the call to your function R(). So Mathcad sees itself confronted to do a vectorization with a 4x1 vector AND a 4x5 matrix and refuses to work as of different dimensions. It shouldn't do so in my opinion but I am not sure if its a bug or just an undesired behaviour.

So the only solution I can think of is to separate the call to your function R() and the squaring of the result. You found two ways to do it and the second one looks quite OK to me. But for whatever it may be worth here is a third one using a two-liner and a temporary local variable:

24.09.png

2 replies

24-Ruby IV
September 23, 2013

Send the sheet pleace!

1-Visitor
September 23, 2013

At the end of the document, there are three definitions for A.

The first uses the definition for R in the function, which is silly since it isn't using the function for which R is defined.

The second uses the matrix R as passed in an argument, and seems to work OK

The third is how I've defined in the image above, where I reference the function definition for R as defined above.

Werner_E25-Diamond IAnswer
25-Diamond I
September 24, 2013

It seems to me that the problem is that if you vectorize the squaring you automatically also vectorize the call to your function R(). So Mathcad sees itself confronted to do a vectorization with a 4x1 vector AND a 4x5 matrix and refuses to work as of different dimensions. It shouldn't do so in my opinion but I am not sure if its a bug or just an undesired behaviour.

So the only solution I can think of is to separate the call to your function R() and the squaring of the result. You found two ways to do it and the second one looks quite OK to me. But for whatever it may be worth here is a third one using a two-liner and a temporary local variable:

24.09.png

1-Visitor
September 24, 2013

Many thanks Werner!