Possible Duplicate:
How do you calculate the average of a set of angles?
If I have a set of bearings, ranging from 1-360, how can I find the average? Usually to find the average one would add them all up and divide by the number of items. The problem here is that doing that in the case of [1, 359], 2 bearings, would result in in 180, which in fact should be 360. Any ideas?
Bearings of lines may be calculated if bearing of one of the lines and the included angles measured clockwise between the various lines are given. Bearing of a line = given bearing + included angle.
How to Calculate Average. The average of a set of numbers is simply the sum of the numbers divided by the total number of values in the set.
Represent the angles as vectors with Norm=1 and average the sum.
x1 = {cos(a),sin(a)}
x2 = {cos(b),sin(b)}
(x1+x2)/2 = {(cos(a)+cos(b))/2,(sin(a)+sin(b))/2}
which means the angle for the mean is
atan2((sin(a)+sin(b)) /(cos(a)+cos(b)))
Just beware of controlling the possible overflow when the denominator is close to zero.
It isn't clear from your question what you're trying to define the "average" to be... for directions on a circle there is no clear-cut obvious notion of average.
One interpretation is the value x
that is the closest fit to the set of provided values, in the least-squares sense, where the distance between two bearings is defined as the smallest angle between them. Here is code to compute this average:
In[2]:= CircDist[a_, b_] := 180 - Mod[180 + a - b, 360]
In[6]:= Average[bearings_] :=
x /. NMinimize[
Sum[CircDist[x, bearings[[i]]]^2, {i, 1, Length[bearings]}],
x][[2]]
In[10]:= Average[{1, 359}]
Out[10]= -3.61294*10^-15
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With