Hello all,
I have two simple functions similar to each other. One of them shows different values correspond to different values of x, but the other one only shows a unique value. I wonder if it is a Mathcad bug. How can I have both functions give me values correspond to those of x?
Solved! Go to Solution.
Luc already explained what happens and that its not a bug but correct mathematical behavior.
Here's what happens in a bit more detail:
Note that in your F2 you use a vector to the power of a scalar. This operation is not defined mathematically! Mathcad could throw an error, but its programmed to switch automatically to implicit vectorization if an operation with vectors makes no sense.
The very same happens in F1 and F2 when you calculate exp(vector). This a not a legitimate mathematical operation and so implicit vecorization is done.
But if you have an expression with vector * vector this makes sense, its interpreted as scallar (inner) product of the two vectors and so the result is a scalar.
You may give it a try: Define a vector v of any size and evaluate v*v and v^2. v*v should yield a scalar, but v^2 (no valid math operation) gives you a vector. You get the same vector if you vectorize v*v.
Its always a good idea to use expplicit vectorization rather than to rely on automatic implicit vectorization.
In F1 you takes the exponent of a vector, which results in a vector.
In F2 you multiply the result of the exponent of a vector with another vector (a vector to some power).
Multiplying two vectors 'normally', results in a single value.
Decide if you need any of the above operations, or use vectorization to get element-by-element operation.
Success!
Luc
Luc already explained what happens and that its not a bug but correct mathematical behavior.
Here's what happens in a bit more detail:
Note that in your F2 you use a vector to the power of a scalar. This operation is not defined mathematically! Mathcad could throw an error, but its programmed to switch automatically to implicit vectorization if an operation with vectors makes no sense.
The very same happens in F1 and F2 when you calculate exp(vector). This a not a legitimate mathematical operation and so implicit vecorization is done.
But if you have an expression with vector * vector this makes sense, its interpreted as scallar (inner) product of the two vectors and so the result is a scalar.
You may give it a try: Define a vector v of any size and evaluate v*v and v^2. v*v should yield a scalar, but v^2 (no valid math operation) gives you a vector. You get the same vector if you vectorize v*v.
Its always a good idea to use expplicit vectorization rather than to rely on automatic implicit vectorization.
Thank you @LucMeekes and @Werner_E for your response. That was really informative. I could solve my problem thanks to your information. I was wondering if you could help me with this problem also (see attached plz). best,
A short analysis:
Success!
Luc