Algosim documentation: mean

mean

Computes the arithmetic mean of all elements in a container or in a sequence. The elements may be numbers, vectors, or matrices.

Syntax

Description

In general, mean(X) = sum(X) / #X.

Summing a container

If X is a non-empty container, then mean(X) is the arithmetic mean of all elements in X.

The following container types are supported:

Typewise, the summands may be either real or complex, and the result is complex iff at least one of the summands is complex.

Summing a sequence

mean(expr, var, a, b) computes the arithmetic mean of the expression expr in one variable var as var takes all integer values from a to b (inclusively).

expr must return a number, a vector, or a matrix.

Notes

These note apply to both modes of operation: summing a container and summing a sequence.

When summing a collection of objects, the objects must be of the same kind (numbers, vectors, or matrices). If they are vectors or matrices, they must all be of the same dimension or size, respectively.

Examples

Summing a container

mean(❨5, 1, 0, 10, 25, 32❩)
12.1666666667	(=73/6)
mean(IdentityMatrix(10))
0.1	(=1/10)
N ≔ 1000; mean(compute(❨cos(2⋅π⋅t/N), sin(2⋅π⋅t/N), t/N❩, t, 0, N − 1))
 ⎛9.05850915112⋅10^−20⎞
e⎜1.68830607047⋅10^−20⎟
 ⎝       0.4995       ⎠

Summing a sequence

N ≔ 1000; mean(❨cos(2⋅π⋅t/N), sin(2⋅π⋅t/N), t/N❩, t, 0, N − 1)
 ⎛9.05850915112⋅10^−20⎞
e⎜1.68830607047⋅10^−20⎟
 ⎝       0.4995       ⎠

See also