Talk:Averages/Mean angle: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
(→‎Accuracy: Created header.)
Line 1: Line 1:

==Accuracy==
Huh, the mean angle of 90, 180, 270 and 360 is "-90.0 degrees"? Doesn't that sound a little fruity? --[[User:Ledrug|Ledrug]] 23:31, 9 July 2012 (UTC)
Huh, the mean angle of 90, 180, 270 and 360 is "-90.0 degrees"? Doesn't that sound a little fruity? --[[User:Ledrug|Ledrug]] 23:31, 9 July 2012 (UTC)
:Well, if done exactly, the mean of those complex numbers should be 0, and then the angle would be, well, undefined, or perhaps whatever default the library picks (like 0). But what is actually happening in this case is that the mean of those complex numbers is not calculated to be exactly 0, due to floating-point error when converting between degrees and radians, and then converting between rectangular and polar coordinates. It is a very small number that is very close to 0
:Well, if done exactly, the mean of those complex numbers should be 0, and then the angle would be, well, undefined, or perhaps whatever default the library picks (like 0). But what is actually happening in this case is that the mean of those complex numbers is not calculated to be exactly 0, due to floating-point error when converting between degrees and radians, and then converting between rectangular and polar coordinates. It is a very small number that is very close to 0

Revision as of 06:36, 10 July 2012

Accuracy

Huh, the mean angle of 90, 180, 270 and 360 is "-90.0 degrees"? Doesn't that sound a little fruity? --Ledrug 23:31, 9 July 2012 (UTC)

Well, if done exactly, the mean of those complex numbers should be 0, and then the angle would be, well, undefined, or perhaps whatever default the library picks (like 0). But what is actually happening in this case is that the mean of those complex numbers is not calculated to be exactly 0, due to floating-point error when converting between degrees and radians, and then converting between rectangular and polar coordinates. It is a very small number that is very close to 0
>>> print sum(rect(1, radians(d)) for d in [90, 180, 270, 360])
-2.28847549044e-17j
The angle is then calculated from whatever nonzero components that this small non-zero number happens to have. Getting an angle from a mean this small is unstable, because any tiny change (perhaps by a different order of calculations, resulting in different behavior of the error) would result in a radically different angle. --Spoon! 05:35, 10 July 2012 (UTC)