Hallo,
can anyone help me with the question how to vectorise this function?
Thank you,
br
Stefan
Solved! Go to Solution.
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.
Hi,
As a result, what do you want? a vector? or a scalar?
Maybe so?
the result should be a Vector. What failure is there in my function?
Best thankx
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.
Werner is my hero 😃
Made my day it works
Thank you