The PTC Community is on temporary read only status in preparation for moving our community to a new platform. Learn more here
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
Solved! Go to Solution.
Vectorization always is applied to ALL vectors involved. So in your approach
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"
or use an auxiliary function for the vectorized multiplication of two factors
Thanks, that works - but I still don't understand why my method gave the error in the first place.
Vectorization always is applied to ALL vectors involved. So in your approach
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"
or use an auxiliary function for the vectorized multiplication of two factors
