Start a topic
With the exception of Windchill, The PTC Community is on read-only status until April 6 in preparation for moving our community to a new platform. Learn more here
cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

The PTC Community is on temporary read only status in preparation for moving our community to a new platform. Learn more here

Translate the entire conversation x

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

RS_10423705
4-Participant

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

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

 

ACCEPTED SOLUTION

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

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

 

 

 

View solution in original post

3 REPLIES 3

image.png

image.png

RS_10423705
4-Participant
(To:ttokoro)

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

Werner_E
25-Diamond I
(To:RS_10423705)

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

 

 

 

Announcements


Top Tags