Skip to main content
15-Moonstone
April 4, 2018
Solved

Why are these expressions evaluating differently?

  • April 4, 2018
  • 2 replies
  • 1740 views

...in one case returning a vector; in the other evaluating only the last entry in vthrow? The expressions  have the same form.

Best answer by JohnRudnicki

Aha. Thanks. That makes sense once you explained it.

2 replies

25-Diamond I
April 4, 2018

No, they don't have the same form!

 

The secret is "automatic vectorization" which Mathcad applies, if an expression/operation would otherwise make no sense when applied to a vector.

 

v^2 is an operation not defined for vectors. So instead of throwing an error message Mathcad applies automatic vectorization. That means it takes every element of the vector v, calculates the expression for this value and collects all those results in a new result vector. Thats the reason you see a vector as result in your first function as neither 1/v^2 nor sin are operations/function defined for vectors.

In you second example the expression in the parenthesis would yield a vector cause of auto vectorization. The expression v/g also yields a vector. And now those two vectors are multiplied. And multiplication IS an operation defined for vectors and so Mathcad return the dot product, a single scalar.

If you want to have that expression evaluated vectorized you would have to explicitly demand it (and I would advise to explicitly apply manual vectorization every time you want it to be done and do not rely on the automatic):

Bild.png

JohnRudnicki15-MoonstoneAuthorAnswer
15-Moonstone
April 4, 2018

Aha. Thanks. That makes sense once you explained it.