Function Repository Resource:

CircularMean

Source Notebook

Compute the mean of a collection of angles

Contributed by: Arnoud Buzing

ResourceFunction["CircularMean"][angles]

computes the circular mean of the given angles.

Details

For a list of angles, ResourceFunction["CircularMean"] gives better results than Mean because it handles the discontinuity of angles near 0 and 2π better.

Examples

Basic Examples

Generate random angles:

In[1]:=
angles = Join[RandomReal[{0, 1}, 100], RandomReal[{2 \[Pi] - 1, 2 \[Pi]}, 100]];

Compute the circular mean:

In[2]:=
cm = ResourceFunction["CircularMean"][angles]
Out[2]=

Compute the mean:

In[3]:=
mn = Mean[angles]
Out[3]=

Compare the two means visually. The blue array represents the circular mean and the red arrow represents the regular mean. Note how the circular mean is a more useful way to compute the mean value for angles:

In[4]:=
Graphics[{
  Point[Transpose[{Cos[angles], Sin[angles]}]],
  Blue, Arrow[{{0, 0}, {Cos[cm], Sin[cm]}}],
  Red, Arrow[{{0, 0}, {Cos[mn], Sin[mn]}}]
  },
 PlotRange -> 1]
Out[4]=

Publisher

Arnoud Buzing

Requirements

Wolfram Language 14.0 (January 2024) or above

Version History

  • 1.0.0 – 04 October 2024

Related Resources

License Information