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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

A simple problem with a bug

mzarrabi
12-Amethyst

A simple problem with a bug

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?

1 ACCEPTED SOLUTION

Accepted Solutions

Luc already explained what happens and that its not a bug but correct mathematical behavior.

Here's what happens in a bit more detail:

Bild1.png

 

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.

 

View solution in original post

4 REPLIES 4
LucMeekes
23-Emerald III
(To:mzarrabi)

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.

LM_20171220_VectorMult.png

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:

Bild1.png

 

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.

 

mzarrabi
12-Amethyst
(To:Werner_E)

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,

LucMeekes
23-Emerald III
(To:mzarrabi)

A  short analysis:

LM_20171222_simple problem.png

 

Success!
Luc

Top Tags