Math.Enum (math v0.7.0) View Source
Math.Enum defines Math-functions that work on any collection extending the Enumerable protocol. This means Maps, Lists, Sets, etc., and any custom collection types as well.
Link to this section Summary
Functions
Calculates the mean of a collection of numbers.
Calculates the median of a given collection of numbers.
Calculates the mode of a given collection of numbers.
Calculates the product, obtained by multiplying all elements in collection with eachother.
Calculates the standard deviation of a given collection of numbers.
Calculates the variance of a given collection of numbers.
Link to this section Functions
Specs
Calculates the mean of a collection of numbers.
This is the sum, divided by the amount of elements in the collection.
If the collection is empty, returns nil
Also see Math.Enum.median/1
Examples
iex> Math.Enum.mean [1,2,3]
2.0
iex> Math.Enum.mean 1..10
5.5
iex> Math.Enum.mean [1,2,3,4,5, -100]
-14.166666666666666
iex> Math.Enum.mean []
nil
Specs
Calculates the median of a given collection of numbers.
- If the collection has an odd number of elements, this will be the middle-most element of the (sorted) collection.
- If the collection has an even number of elements, this will be mean of the middle-most two elements of the (sorted) collection.
If the collection is empty, returns nil
Also see Math.Enum.mean/1
Examples
iex> Math.Enum.median [1,2,3]
2
iex> Math.Enum.median 1..10
5.5
iex> Math.Enum.median [1,2,3,4,5, -100]
2.5
iex> Math.Enum.median [1,2]
1.5
iex> Math.Enum.median []
nil
Specs
Calculates the mode of a given collection of numbers.
Always returns a list. An empty input results in an empty list. Supports bimodal/multimodal collections by returning a list with multiple values.
Examples
iex> Math.Enum.mode [1, 2, 3, 4, 1]
[1]
iex> Math.Enum.mode [1, 2, 3, 2, 3]
[2, 3]
iex> Math.Enum.mode []
[]
Calculates the product, obtained by multiplying all elements in collection with eachother.
Examples
iex> Math.Enum.product [1,2,3]
6
iex> Math.Enum.product 1..10
3628800
iex> Math.Enum.product [1,2,3,4,5, -100]
-12000
Specs
Calculates the standard deviation of a given collection of numbers.
If the collection is empty, returns nil
Examples
iex> Math.Enum.stdev([1,2,3,4,5])
1.4142135623730951
iex> Math.Enum.stdev 1..10
2.8722813232690143
iex> Math.Enum.stdev [1,2,3,4,5,-100]
38.407536876098796
iex> Math.Enum.stdev []
nil
Specs
Calculates the variance of a given collection of numbers.
If the collection is empty, returns nil
Examples
iex> Math.Enum.variance [1, 2, 3, 4, 5]
2.0
iex> Math.Enum.variance 1..10
8.25
iex> Math.Enum.variance [1, 2, 3, 4, 5, -100]
1475.138888888889
iex> Math.Enum.variance []
nil