Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I have an expression that needs to evaluate sin (x)/x for x =0. I was doing this with simple program with if's
But Luc suggested I use sinc
I know these are the same and even checked by evaluating them numerically. But if I use the sinc expression, it must mess up something later in the worksheet because the results are completely different. (And it is the form with the if's that I know is correct.). I cannot figure out what is happening. Since I have a version that works, maybe I should just ignore the issue and move on, but, if someone can help, I would like to know what is going on.
I have posted the worksheets in MC14 and MC11. Both contain the expressions for PHI but evaluation is disabled for the sinc form. Results are given in graphs at the bottom of the worksheets.
Solved! Go to Solution.
Ahh, I got it!
Problem was that your calculation relied on Mathcad doing implicit vectorization.
You called "disp" and so also "SS" and "PHI" with a vector xi of values but did not explicitly apply vectorization. This worked well with the original formulation of PHI, but failed with the version using sinc becasue here we read sinc(kk*acos(xi) * acos(xi). If xi is a vector, both factors are vectors as well and Mathcad of course will not apply implicit vectorization but rather applies the vector dot product.
Solution is to use vectorization in the definition of function "disp"
OR as an alternative vectorise in the definition of function SS
You don't have to do both but it does no harm if you do.
Another option would be to do the vectorization already in the definition of PHI
Applying vectorisation either way makes you alternative definition of PHI work as well as will my variation of it which I posted above.
These are errors that are not so easy to find and I therefore feel confirmed in my opinion that one should not rely on Mathcad doing implicit vectorisation but rather ALWAYS use explicit vectorization when calling a function written for a scalar argument with a vector as argument and expecting the vector elements to be processed individually.
Here you see the difference between between calling with and without explicit vectorization:
It was my variant of PHI that led me on the right track, because I was initially wondering why “u” was not a vector here, whereas it was a vector in the original variant of PHI and also in your sinc variant (albeit with incorrect values).
MC11 sheet attached
Hi Joihn,
The 'MC11' file is still an MC14 file, it's xmcd...
Luc
I have not looked in detail in your calculations but from first sight the two functions PHI you defined should be equivalent. But I sure can confirm that things go havoc when using the definition using sinc.
I tried to write PHI with sinc a bit more efficient (avoiding calculation of acos(xi) multiple times) and using this function
things even got worse as variable u now is not a vector of values but just one single scalar.
Could not spot what causes the difference.
I attach the file in MC11 format for Luc.
Ahh, I got it!
Problem was that your calculation relied on Mathcad doing implicit vectorization.
You called "disp" and so also "SS" and "PHI" with a vector xi of values but did not explicitly apply vectorization. This worked well with the original formulation of PHI, but failed with the version using sinc becasue here we read sinc(kk*acos(xi) * acos(xi). If xi is a vector, both factors are vectors as well and Mathcad of course will not apply implicit vectorization but rather applies the vector dot product.
Solution is to use vectorization in the definition of function "disp"
OR as an alternative vectorise in the definition of function SS
You don't have to do both but it does no harm if you do.
Another option would be to do the vectorization already in the definition of PHI
Applying vectorisation either way makes you alternative definition of PHI work as well as will my variation of it which I posted above.
These are errors that are not so easy to find and I therefore feel confirmed in my opinion that one should not rely on Mathcad doing implicit vectorisation but rather ALWAYS use explicit vectorization when calling a function written for a scalar argument with a vector as argument and expecting the vector elements to be processed individually.
Here you see the difference between between calling with and without explicit vectorization:
It was my variant of PHI that led me on the right track, because I was initially wondering why “u” was not a vector here, whereas it was a vector in the original variant of PHI and also in your sinc variant (albeit with incorrect values).
MC11 sheet attached
Thanks. I never would have found that but happy to have provided with you with a challenge 😀. I seldom think to use vectorization and never got proficient with it, but will try to take your advice for the future.