Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
Dear all,
I am using the direction cosines to find angle (or rather, the change in angle) along a curve at specific points.
But when the first part is a straight line, the change in angle should be zero (cos(theta) = 1.000) but mathcad is giving me cos(theta) = 1.00000000000000000000000000000000000000000000000001 or something and because of this, when I use the "acos" function, I am getting imaginary angles.
Currently I just added a 10^-20 to the denominator and the problem seemed to go away (maybe). But is there any way I can avoid this altogether ?
The calculation sheet is attached below. Please dont mind the extreme decimal values for the "y" variables. I am reading them from a curve and so they are like that :).
Many thanks in advance !
Warm Regards,
Aravind.
Solved! Go to Solution.
Here are four ways to deal with this round-off error:
1) use symbolic calculation, follow the costheta expression by a symbolic eval
2) use symbolic calc, right click the expression and chose "Optimize"
3) Round the result of costheta to just 15 decimals (guess this is the approach which directly addresses the problem)
4) Only use the real part of the angle
I understand that you use a formula to calculate cos(theta). When calculating numerically, you ALWAYS have to deal with uncertainty.
A 1 is a 1, but when it comes from e.g. 9 * (1/3)^, it might result in something slightly different from 1, due to internal representation of numbers.
To limit the result between -1 and 1, you could use:
cos_theta:=min( max( -1, expression), 1)
Where 'expression' is the formula you use to calculate cos(theta).
Success!
Luc
That would work just fine.
Thanks LucMeekes ! It's a shame I can't mark two answers as solutions 🙂
Here are four ways to deal with this round-off error:
1) use symbolic calculation, follow the costheta expression by a symbolic eval
2) use symbolic calc, right click the expression and chose "Optimize"
3) Round the result of costheta to just 15 decimals (guess this is the approach which directly addresses the problem)
4) Only use the real part of the angle
Hi Werner,
Thanks for the multiple solutions 🙂