Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Hi,
Solved! Go to Solution.
I am not sure why is not seen the text of the first message, but here is:
I am sure that something I do not do correctly, I believe there with that condition of an=0.
How to achieve the result of second vector (the correct one below)?
Prime 10 file attached (in first post)
So only without = after it, you can get all what you want.
As @ttokoro had shown you are running into numerical inaccuracies, presumably because of the numeric integration used.
You can make these inaccuracies/round-offs visible using symbolic evaluation:
So the values you believe being zero aren't zero and that's the reason "atan" yields a 'valid' result.
BTW, using a:=a= and b:=b= is mandatory as otherwise you won't see the errors of the numeric calculation but rather just the errors the symbolic calculations makes, too. In @ttokoro 's screenshot you only see the errors made by symbolic calculation!
So the solution is either
1) using a threshold as seen in @ttokoro 's picture, but I would strongly suggest to use the absolute value function because the round-off can be in any direction ->
2) or simply rounding the values to a degree which is acceptable for you.
I also wonder why you would bother with the range variable instead of simply using vectorization and why you don't use the "atan2" function instead of "atan".
"atan2" catches the 'error' when a=0 and return the correct 90°. It still throws an error if both values are zero because in mathematical definition the angle is undefined in that case. So it may be a good idea to define an "Atan2" function which catches this error as well. Of course you could change it to return 0 instead of NaN in case both values are zero if this is more convenient for your application.
BTW, of course the last but one value must be -90° and not +90° as you screenshot claims!
BTW, why not using a more generic approach like
You get the correct value for the angles either by using symbolic evaluation
or without using symbolics again by using rounded values