cancel
Showing results for
Did you mean:
cancel
Showing results 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

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
24-Ruby V
(To:sm�ller-2)

Guess you are looking for something like this:

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.

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.

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

Hi,

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

Maybe so?

11-Garnet
(To:-MFra-)

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

Best thankx

24-Ruby V
(To:sm�ller-2)

Guess you are looking for something like this:

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.

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.

11-Garnet
(To:Werner_E)

Werner is my hero 😃