Centroid of a set of N-dimensional points

From Rosetta Code
Revision as of 23:32, 15 July 2023 by Wherrera (talk | contribs) (gr)
Centroid of a set of N-dimensional points is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

In analytic geometry, the centroid of a set of points is a point in the same domain as the set. The centroid point is chosen to show a property which can be calculated for that set.

Consider the centroid defined as the arithmetic mean of a set of points of arbitrary dimension.

Task

Create a function in your chosen programming language to calculate such a centroid using an arbitrary number of points of arbitrary dimension.

Test your function with the following groups of points
one-dimensional: (1), (2), (3)
two-dimensional: (8, 2), (0, 0)
three-dimensional: the set (5, 5, 0), (10, 10, 0) and the set (1, 3.1, 6.5), (-2, -5, 3.4), (-7, -4, 9), (2, 0, 3)
five-dimensional: (0, 0, 0, 0, 1), (0, 0, 0, 1, 0), (0, 0, 1, 0, 0), (0, 1, 0, 0, 0)


Stretch task
   Show a 3D plot image of the second 3-dimensional set and its centroid.
See Also
[Wikipedia page]
[Wolfram Mathworld on Centroid]