cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

14-Alexandrite

## Why are these expressions evaluating differently?

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

1 ACCEPTED SOLUTION

Accepted Solutions
14-Alexandrite
(To:JohnRudnicki)

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

2 REPLIES 2
24-Ruby V
(To:JohnRudnicki)

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):

14-Alexandrite
(To:JohnRudnicki)

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

Announcements