Skip to main content
4-Participant
February 20, 2026
Solved

Mathcad error, having trouble in Prime 11 creating functions that use vectorized multiplication of two vectors

  • February 20, 2026
  • 1 reply
  • 113 views

Hi all,

 

I'm a long time user of Mathcad but first time poster - hoping someone can tell me where I'm going wrong!

 

I'm having trouble in Prime 11 creating functions that use vectorized multiplication of two vectors, where the values inside one of the vectors was created using the sum operator. When I do the equivalent operation directly within the worksheet (i.e. not within a function it works without error. When I try replacing the sum operator within the function with a value it all works without error.

 

The error message I get is "This value must be a matrix of scalar elements all of which have the same units"

 

I've seen a lot of discussion about how this error can come from inappropriate use of ranges when vectors should be used - I've checked using IsArray & IsRange on all the vectors involved and I don't think I have any inadvertent ranges.

 

Example worksheet showing my issue attached.

 

If anyone can help tell me where I'm going wrong I'd be really grateful, I've been struggling with this for a while!

 

Thanks

Robbie

RS_10423705_0-1771558833400.png

 

Best answer by Werner_E

Vectorization always is applied to ALL vectors involved. So in your approach

grafik.png

its applied to the first occurrence of "a" as well, which means that only one element of vector "a" is fed as argument in function "func1". This makes function "func1" fail because the sum operator used there can only be applied to a vector, not to a single scalar.

There is no simple way to tell Prime that vectorization should not be applied to the first occurrence of "a" but only to the multiplication of the outcome of function "func1" and the second occurrence of "a". Or better said there is no way to tell Prime that vectorization should be applied to the multiplication but not at the function call used in the first factor of this multiplication.

 

Of course you could chose a two-step approach using "programming"

 

 

grafik.png

or use an auxiliary function for the vectorized multiplication of two factors

grafik.png

 

 

 

1 reply

ttokoro
21-Topaz I
21-Topaz I
February 20, 2026

image.png

image.png

t.t.
4-Participant
February 20, 2026

Thanks, that works - but I still don't understand why my method gave the error in the first place.

Werner_E25-Diamond IAnswer
25-Diamond I
February 20, 2026

Vectorization always is applied to ALL vectors involved. So in your approach

grafik.png

its applied to the first occurrence of "a" as well, which means that only one element of vector "a" is fed as argument in function "func1". This makes function "func1" fail because the sum operator used there can only be applied to a vector, not to a single scalar.

There is no simple way to tell Prime that vectorization should not be applied to the first occurrence of "a" but only to the multiplication of the outcome of function "func1" and the second occurrence of "a". Or better said there is no way to tell Prime that vectorization should be applied to the multiplication but not at the function call used in the first factor of this multiplication.

 

Of course you could chose a two-step approach using "programming"

 

 

grafik.png

or use an auxiliary function for the vectorized multiplication of two factors

grafik.png