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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

How to vectorise

sm�ller-2
11-Garnet

How to vectorise

Hallo,

can anyone help me with the question how to vectorise this function?

Thank you,

br

Stefan

1 ACCEPTED SOLUTION

Accepted Solutions

Guess you are looking for something like this:

B1.png

While this works I would much more favor an approach, where all functions are written just for scalar arguments and have all variables they depend on as function argument. After all all the calculations your functions are doing are basically intended to be done with scalars, not with vectors. So the functions should be set up that way and should use no vectorization.

Later those function could be be called vectorized with vectors as arguments and you can always call those function also with simple scalar arguments to check or to quickly play with different values.

Doing so also avoids problems like the one you ran into.

 B2.png

Reason for the effect you experience is, that your vectorized call of sigma.rRf  not only vectorizes F.b but also vectorizes D. So sigma.rRA is not fed with the vector D, as you intended, but with a single scalar, a component of D. The result is a vector, as sigma.rRA unfortunately uses vectors for its calculations. This vector is multiplied by the appropriate component of F.b and the result for every of these five calls is a vector. Thats the reason your function presents you with a nested vector as result.

View solution in original post

4 REPLIES 4
-MFra-
21-Topaz II
(To:sm�ller-2)

Hi,

As a result, what do you want? a vector? or a scalar?

Maybe so?

maybeso.jpg

the result should be a Vector. What failure is there in my function?

 

Best thankx

Guess you are looking for something like this:

B1.png

While this works I would much more favor an approach, where all functions are written just for scalar arguments and have all variables they depend on as function argument. After all all the calculations your functions are doing are basically intended to be done with scalars, not with vectors. So the functions should be set up that way and should use no vectorization.

Later those function could be be called vectorized with vectors as arguments and you can always call those function also with simple scalar arguments to check or to quickly play with different values.

Doing so also avoids problems like the one you ran into.

 B2.png

Reason for the effect you experience is, that your vectorized call of sigma.rRf  not only vectorizes F.b but also vectorizes D. So sigma.rRA is not fed with the vector D, as you intended, but with a single scalar, a component of D. The result is a vector, as sigma.rRA unfortunately uses vectors for its calculations. This vector is multiplied by the appropriate component of F.b and the result for every of these five calls is a vector. Thats the reason your function presents you with a nested vector as result.

Werner is my hero 😃

Made my day it works

 

Thank you

Top Tags