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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Multiplying range variables doesn't work

TS_9501702
4-Participant

Multiplying range variables doesn't work

x should have more values depending on t. Why do I only get 1 value?

If I separate the terms they work as they should

TS_9501702_3-1617453886858.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

First let me say that whenever possible you should always attach the worksheet itself.

 

You defined a range t and in the same region you numerically evaluated it (the = sign after the definition). This is an undocumented trick to turn a range into a vector.

So t is a vector.

x is defined as a product of two factors and as you show yourself in the last line, both factors are vectors. And the "normal" product of two vectors is ... one single scalar (dot product, scalar product).

To get the result you expect, you must vectorize (the arrow operator over an expression) the right hand side of the definition of x.

Keep in mind that e^t actually should throw an error because there is no definition in math to take a number to the power of a vector. Prime instead applies automatic implicit vectorization in that case (also applies to sin(t), etc) and evaluates that expression for each vector el/ement in a row and collects the various results in its result  vector - excactly what you had in mind. Multiplication on the other hand is an operation defined for vectors and if you want it to be executed elementwise again, you must manually vectorize the operation.#

View solution in original post

3 REPLIES 3

First let me say that whenever possible you should always attach the worksheet itself.

 

You defined a range t and in the same region you numerically evaluated it (the = sign after the definition). This is an undocumented trick to turn a range into a vector.

So t is a vector.

x is defined as a product of two factors and as you show yourself in the last line, both factors are vectors. And the "normal" product of two vectors is ... one single scalar (dot product, scalar product).

To get the result you expect, you must vectorize (the arrow operator over an expression) the right hand side of the definition of x.

Keep in mind that e^t actually should throw an error because there is no definition in math to take a number to the power of a vector. Prime instead applies automatic implicit vectorization in that case (also applies to sin(t), etc) and evaluates that expression for each vector el/ement in a row and collects the various results in its result  vector - excactly what you had in mind. Multiplication on the other hand is an operation defined for vectors and if you want it to be executed elementwise again, you must manually vectorize the operation.#

TS_9501702
4-Participant
(To:Werner_E)

Thank you for your answer! After some trial and error with easy examples I realised that multiplying 2 vectors results in multiplying both elements from the respectiv row and adding them up.  The way I managed to fix this is by turning it into a function.

 

TS_9501702_0-1617461639039.png

In case it might help someone


@TS_9501702 wrote:

Thank you for your answer! After some trial and error with easy examples I realised that multiplying 2 vectors results in multiplying both elements from the respectiv row and adding them up. 


Yes, thats exactly what vector dot product (inner product, scalar product) means 😉

And if you apply vectorization, you get the result you expected. See her for comparison:

Werner_E_0-1617473352417.png

But turning the calculation into a function as you finally did usually is the better approach anyway. You need the t-range just for plotting and you sure should choose a smaller step-width:

Werner_E_1-1617473456662.png

 

 

Top Tags